Skip to content

How To: Use New Class Based API Mutations with Old Define Style API

Scott Walkinshaw edited this page Jul 11, 2018 · 3 revisions

In a legacy app, you may wish to mix old/new style mutations. A few changes are required:

Opt your Schema into the new API (it's backwards compatible, while the old API is not forwards compatible):

- Schema = GraphQL::Schema.define
+ class Schema < GraphQL::Schema

Opt your base mutation class into the new API:

- MutationType = GraphQL::ObjectType.define do
-   name "Mutation"
+ class MutationType < GraphQL::Schema::Object
+   graphql_name "Mutation"

Leave old mutations alone and create new mutations using the new syntax:

field :old, field: OldMutation.field
+ field :new, mutation: NewMutation

This will help you avoid type must return GraphQL::BaseType, not NilClass (nil) style errors.