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 Elixir's graphql library.
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
-
Add graphql_relay to your list of dependencies in
mix.exs
:def deps do [{:graphql_relay, "~> 0.0.17"}] end
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.
In other words, Relay requires a schema.json
file which is generated server-side, so we need a way of creating and updating this file.
We need to set two configuration values which you can do in the config/config.exs
for the project you're using this library in.
config :graphql_relay,
schema_module: GraphQL.Schema.Root, # Module that includes a `schema` function that returns your GraphQL schema
schema_json_path: "#{Path.dirname(__DIR__)}/priv/repo/graphql" # Will create a `schema.json` file in this directory
With this configuration set you can now run the GraphQL.Relay.generate_schema_json!
function from your project's root directory: mix run -e GraphQL.Relay.generate_schema_json!
If you're using this library in a Phoenix project you can set up your Phoenix dev environment to run this automatically after each modification to a GraphQL related schema file.
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.
- React [and Relay] Developer Tools for Chrome and Firefox.