Generators

If you’re using GraphQL with Ruby on Rails, you can use generators to:

graphql:install

You can add GraphQL to a Rails app with graphql:install:

rails generate graphql:install

This will:

After installing you can see your new schema by:

Options

Scaffolding Types

Several generators will add GraphQL types to your project. Run them with -h to see the options:

ActiveRecord columns auto-extraction

The graphql:object and graphql:input generators can detect the existence of an ActiveRecord class with the same name, and scaffold all database columns as fields/arguments using appropriate GraphQL types and nullability detection

Options

Scaffolding Mutations

You can prepare a Relay Classic mutation with

rails g graphql:mutation #{mutation_name}

Scaffolding ActiveRecord Mutations

You can generate a Relay Classic create, update or delete mutation for a given model with

rails g graphql:mutation_create #{model_class_name}
rails g graphql:mutation_update #{model_class_name}
rails g graphql:mutation_delete #{model_class_name}

model_class_name accepts both namespace/class_type and Namespace::ClassType formats. This mutation also accepts the --namespaced-types flag, to keep it consistent with the scaffolded Object and Input classes from the type generators

Scaffolding Loaders

You can prepare a GraphQL::Batch loader with

rails g graphql:loader