# 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 <a href="">when you don't use this library</a> and <a href="">when you do use it</a>.

This library relies on Elixir's <a href="">graphql</a> library.

## 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.

* <a href="">GraphQL Introduction</a>
* <a href="">GraphQL: A data query language</a>
* <a href="">Your First GraphQL Server</a>
* <a href="">Learn GraphQL</a>
* <a href="">GraphQL Specification</a>
* <a href="">Relay</a>
* <a href="">A Cartoon Guide To Facebook's Relay</a>

## Installation

  1. Add graphql_relay to your list of dependencies in `mix.exs`:

        def deps do
            {:graphql_relay, "~> 0.0.16"},
            {:plug_graphql, "~> 0.2"} # Most likely going to need this as well

## Configuration

Relay's Babel Plugin (<a href="">Relay Docs</a>, <a href="">npm</a>) and babel-relay-plugin-loader (<a href="">npm</a>, <a href="">GitHub</a>) 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 <a href="">set up your Phoenix dev environment to run this automatically after each modification to a GraphQL related schema file</a>.

## Usage

See the <a href="">Star Wars test schema</a> for a simple example and the <a href="">TodoMVC example Phoenix application</a> for a full application example that uses Ecto as well.

* <a href="">How to do authentication and authorization in a Phoenix application with GraphQL</a>

## Helpful Tools

* <a href="">React [and Relay] Developer Tools</a> for Chrome and Firefox.