Graphql-ruby objects

From wikinotes
Revision as of 21:42, 5 September 2021 by Will (talk | contribs)

Fields

All objects in graphql are exposed using fields.
Mutations are added as fields to the root Mutation object,
and Queries are added to the root Query object.

Fields

class User < GraphQL::Schema::Object
  field :id, Integer    # name, returntype
  field :age, Integer   # name, returntype
end

Parametrized Fields

class MyGraph < GraphQL::Schema::Object
  field :user, User, do |field|
    field.argument(:id, Integer, required: true)
  end
end