Code Monkey home page Code Monkey logo

graphql_relay's Introduction

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

graphql_relay's People

Contributors

cgiffard avatar dre1080 avatar seanabrahams avatar thaterikperson avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.