field :id, !types.ID field :title, !types.String field :body, !types.String field :author, !AuthorType field :comments, types[!CommentType] field :teaser, types.String, "The teaser of the Post" do resolve ->(post, args, ctx) { post.body[0, 40] } end end
of this schema" field :post do type PostType argument :id, !types.ID description "Find a Post by ID" resolve ->(obj, args, context) { Post.find(args["id"]) } end field :posts do type types[PostType] resolve ->(obj, args, context) { Post.all } end end Schema = GraphQL::Schema.define do query QueryType end
description "Adds a Post." argument :post, PostInputType resolve ->(t, args, c) { Post.create( title: args['post']['title'], body: args['post']['body'] ) } end end Schema = GraphQL::Schema.define do mutation MutationRoot end
name } } } } QueryType = GraphQL::ObjectType.define do name "Query" description "The query root of this schema" field :post do type PostType argument :id, !types.ID description "Find a Post by ID" resolve ->(obj, args, context) { Post.find(args["id"]) } end field :posts do type types[PostType] resolve ->(obj, args, context) { Post.all } end end
name } } } } QueryType = GraphQL::ObjectType.define do name "Query" description "The query root of this schema" field :post do type PostType argument :id, !types.ID description "Find a Post by ID" resolve ->(obj, args, context) { Post.find(args["id"]) } end field :posts do type types[PostType] resolve ->(obj, args, context) { Post.all } end end
name } } } } PostType = GraphQL::ObjectType.define do name "Post" description "A blog post" field :id, !types.ID field :title, !types.String field :body, !types.String field :author, !AuthorType field :comments, types[!CommentType] field :teaser, types.String, do resolve ->(post, args, ctx) { post.body[0, 40] } end end
def perform(ids) @model.where(id: ids).each { |record| fulfill(record.id, record) } ids.each { |id| fulfill(id, nil) unless fulfilled?(id) } end end # Then, in your type definition field :author, !AuthorType do resolve -> (post, args, context) { RecordLoader.for(Author).load(post.author_id) } end
top_secret) # OR filter = PermissionWhitelist.new(@current_user) MySchema.execute(query_string, only: filter) class PermissionWhitelist def initialize(user) @user = user end def call(schema_member, ctx) Permissions.allowed?(user, schema_member) end end