If you’re using GraphQL with Ruby on Rails, you can use generators to:
You can add GraphQL to a Rails app with graphql:install
:
rails generate graphql:install
This will:
app/graphql/
Query
type definitionMutation
type definition with a base mutation classgraphiql-rails
After installing you can see your new schema by:
bundle install
rails server
localhost:3000/graphiql
--relay
will add Relay-specific code to your schema--batch
will add GraphQL::Batch to your gemfile and include the setup in your schema--no-graphiql
will exclude graphiql-rails
from the setup--schema=MySchemaName
will be used for naming the schema (default is #{app_name}Schema
)Several generators will add GraphQL types to your project. Run them with -h
to see the options:
rails g graphql:object
rails g graphql:interface
rails g graphql:union
rails g graphql:enum
rails g graphql:scalar
You can prepare a Relay Classic mutation with
rails g graphql:mutation #{mutation_name}
You can prepare a GraphQL::Batch loader with
rails g graphql:loader