Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

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 a schema 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.

Helpful Tools

About

Relay helpers for GraphQL Elixir

Resources

License

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages

You can’t perform that action at this time.