All Projects → vue-relay → Vue Relay

vue-relay / Vue Relay

Licence: bsd-2-clause
🖖 🔛 🗂 A framework for building GraphQL-driven Vue.js applications.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Relay

Frontend
🌏 The front-end application code for https://buildkite.com
Stars: ✭ 132 (+25.71%)
Mutual labels:  graphql, relay, frontend
Graphql Config
One configuration for all your GraphQL tools (supported by most tools, editors & IDEs)
Stars: ✭ 883 (+740.95%)
Mutual labels:  graphql, relay
Lighthouse Utils
An add-on to Lighthouse to auto-generate CRUD actions from types https://github.com/nuwave/lighthouse
Stars: ✭ 26 (-75.24%)
Mutual labels:  graphql, relay
Magiql
🌐 💫 Simple and powerful GraphQL Client, love child of react-query ❤️ relay
Stars: ✭ 45 (-57.14%)
Mutual labels:  graphql, relay
Js Graphql Intellij Plugin
GraphQL language support for WebStorm, IntelliJ IDEA and other IDEs based on the IntelliJ Platform.
Stars: ✭ 686 (+553.33%)
Mutual labels:  graphql, relay
Adrenaline
Simple Relay alternative
Stars: ✭ 720 (+585.71%)
Mutual labels:  graphql, relay
Relay Fullstack
☝️🏃 Modern Relay Starter Kit - Integrated with Relay, GraphQL, Express, ES6/ES7, JSX, Webpack, Babel, Material Design Lite, and PostCSS
Stars: ✭ 986 (+839.05%)
Mutual labels:  graphql, relay
Ethql
A GraphQL interface to Ethereum 🔥
Stars: ✭ 547 (+420.95%)
Mutual labels:  graphql, frontend
Rpg Boilerplate
Relay (React), Postgres, and Graphile (GraphQL): A Modern Frontend and API Boilerplate
Stars: ✭ 62 (-40.95%)
Mutual labels:  graphql, relay
Cynthesize Frontend
Frontend written in Angular 7 and deployed GraphQL for Cynthesize. Development build: https://cynthesize-develop.netlify.com
Stars: ✭ 65 (-38.1%)
Mutual labels:  graphql, frontend
Relay Northwind App
A complex React, Relay, GraphQL demo app. Online demo:
Stars: ✭ 104 (-0.95%)
Mutual labels:  graphql, relay
Este
This repo is suspended.
Stars: ✭ 5,467 (+5106.67%)
Mutual labels:  graphql, relay
Graphqlbundle
This bundle provides tools to build a complete GraphQL server in your Symfony App.
Stars: ✭ 628 (+498.1%)
Mutual labels:  graphql, relay
Graphene
GraphQL framework for Python
Stars: ✭ 6,964 (+6532.38%)
Mutual labels:  graphql, relay
React App
Create React App with server-side code support
Stars: ✭ 614 (+484.76%)
Mutual labels:  graphql, relay
Learnrelay
Learn Relay - A comprehensive introduction to Relay (created by Graphcool)
Stars: ✭ 887 (+744.76%)
Mutual labels:  graphql, relay
Graphql Relay Js
A library to help construct a graphql-js server supporting react-relay.
Stars: ✭ 1,331 (+1167.62%)
Mutual labels:  graphql, relay
Graphql Crunch
Reduces the size of GraphQL responses by consolidating duplicate values
Stars: ✭ 472 (+349.52%)
Mutual labels:  graphql, relay
Graphql Ruby
Ruby implementation of GraphQL
Stars: ✭ 4,931 (+4596.19%)
Mutual labels:  graphql, relay
Graphql Query Test Mock
Easily mock GraphQL queries in your Relay Modern / Apollo / any-other-GraphQL-client tests.
Stars: ✭ 49 (-53.33%)
Mutual labels:  graphql, relay

vue-relay

A framework for building GraphQL-driven Vue.js applications.

npm

Introduction

Installation and Setup

Installation

Install Vue and Relay using yarn or npm:

yarn add vue vue-relay

Set up babel-plugin-relay

Relay Modern requires a Babel plugin to convert GraphQL to runtime artifacts:

yarn add --dev babel-plugin-relay graphql

Add "relay" to the list of plugins your .babelrc file:

{
  "plugins": [
    "relay"
  ]
}

Please note that the "relay" plugin should run before other plugins or presets to ensure the graphql template literals are correctly transformed. See Babel's documentation on this topic.

Set up relay-compiler

Relay's ahead-of-time compilation requires the Relay Compiler, which you can install via yarn or npm:

yarn add --dev relay-compiler graphql

This installs the bin script relay-compiler in your node_modules folder. It's recommended to run this from a yarn/npm script by adding a script to your package.json file:

"scripts": {
  "relay": "relay-compiler --src ./src --schema ./schema.graphql"
}

Then, after making edits to your application files, just run the relay script to generate new compiled artifacts:

yarn run relay

Note: relay-compiler does not understand single-file components with a .vue extension. You can export graphql template literals in .js files, and then import them in .vue single-file components.

For more details, check out Relay Compiler docs.


API Reference

<QueryRenderer />

Props

  • environment: The Relay Environment
  • query: The graphql tagged query. Note: To enable compatibility mode, relay-compiler enforces the query to be named as <FileName>Query. Optional, if not provided, an empty props object is passed to the render callback.
  • variables: Object containing set of variables to pass to the GraphQL query, i.e. a mapping from variable name to value. Note: If a new set of variables is passed, the QueryRenderer will re-fetch the query.

Scoped Slot Props

  • props: Object containing data obtained from the query; the shape of this object will match the shape of the query. If this object is not defined, it means that the data is still being fetched.
  • error: Error will be defined if an error has occurred while fetching the query.
  • retry: Reload the data. It is null if query was not provided.

Example

<!-- Example.vue -->
<template>
  <query-renderer :environment="environment" :query="query" :variables="variables" v-slot="{ props, error, retry }">
    <div v-if="error">{{ error.message }}</div>
    <div v-else-if="props">{{ props.page.name }} is great!</div>
    <div v-else>Loading</div>
  </query-renderer>
</template>

<script>
import { QueryRenderer, graphql } from 'vue-relay'

export default {
  name: 'example',
  components: {
    QueryRenderer
  },
  data () {
    return {
      environment: ..., // https://relay.dev/docs/en/relay-environment.html
      query: graphql`
        query ExampleQuery($pageID: ID!) {
          page(id: $pageID) {
            name
          }
        }
      `,
      variables: {
        pageID: '110798995619330'
      }
    }
  }
}
</script>

Fragment Container

createFragmentContainer([component, ]fragmentSpec)

Props

  • fragments as specified by the fragmentSpec

Component / Scoped Slot Props

{
  relay: {
    environment,
  },
  // Additional props as specified by the fragmentSpec
}

Refetch Container

createRefetchContainer([component, ]fragmentSpec, refetchQuery)

Props

  • fragments as specified by the fragmentSpec

Component / Scoped Slot Props

{
  relay: {
    environment,
    refetch(),
  },
  // Additional props as specified by the fragmentSpec
}

Pagination Container

createPaginationContainer([component, ]fragmentSpec, connectionConfig)

Props

  • fragments as specified by the fragmentSpec

Component / Scoped Slot Props

{
  relay: {
    environment,
    hasMore(),
    isLoading(),
    loadMore(),
    refetchConnection()
  },
  // Additional props as specified by the fragmentSpec
}

Comparison with react-relay

  • QueryRenderer does not take render function.
  • Container creating functions take component as an optional argument.
    • If provided, a conatiner will pass props to the given component.
    • If ommited, a conatiner will pass props to its default scoped slot.

Other APIs

Other APIs are exactly same as Relay's Public APIs. Please refer to Relay's documentation.


Example

The vue-relay-examples repository contains an implementation of TodoMVC. To try it out:

git clone https://github.com/ntkme/vue-relay-examples.git
cd vue-relay-examples/todo
npm install
npm run build
npm start

License

vue-relay is BSD-2-Clause licensed.

Relay is MIT licensed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].