Awesome
GraphQL.Relay
This library contains helper functions that make it easier to setup a Relay compatible GraphQL schema.
You do not need this library to create a Relay compatible GraphQL schema, it just makes it easier. To illustrate this point here's what a Relay compatible schema looks like when you don't use this library and when you do use it.
This library relies on the GraphQL Elixir library.
Installation
Add graphql_relay
to your list of dependencies in mix.exs
:
def deps do
[{:graphql_relay, "~> 0.5"}]
end
Configuration
Relay requires a schema.json
file which is generated server-side, so we need a way of creating and updating this file.
In config/config.exs
add the following config:
config :graphql_relay,
schema_module: MyApp.Schema,
schema_json_path: "#{Path.dirname(__DIR__)}/priv/graphql"
MyApp.Schema
is a module with aschema
function that returns your GraphQL schema- The
schema_json_path
is where the generated JSON schema lives
Generate your schema with:
mix run -e GraphQL.Relay.generate_schema_json!
Phoenix Integration
In Phoenix you can generate the schema automatically after each modification to a GraphQL related schema file in the dev environment:
Babel and Relay
Relay's Babel Plugin (Relay Docs, npm) and babel-relay-plugin-loader
(npm, GitHub) rely on a schema.json
file existing that contains the result of running the full GraphQL introspection query against your GraphQL endpoint. Babel needs this file for transpiling GraphQL queries for use with Relay.
Usage
See the Star Wars test schema for a simple example and the TodoMVC example Phoenix application for a full application example that uses Ecto as well.
Learning GraphQL and Relay
It's important that you understand GraphQL first and then Relay second. Relay is simply a convention for how to organize a GraphQL schema so that Relay clients can query the GraphQL server in a standard way.
- GraphQL Introduction
- GraphQL: A data query language
- Your First GraphQL Server
- Learn GraphQL
- GraphQL Specification
- Relay
- A Cartoon Guide To Facebook's Relay
Helpful Tools
- React [and Relay] Developer Tools for Chrome and Firefox.