Last active
May 12, 2019 18:08
-
-
Save valikos/8c5001b8452711f2c532bf16231c2446 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MySchema < GraphQL::Schema | |
# Required: | |
query Types::Query | |
# Optional: | |
mutation Types::Mutation | |
subscription Types::Subscription | |
end | |
# app/graphql/types/query_type.rb | |
class Types::QueryType < GraphQL::Schema::Object | |
field :character, Types::CharacterType, resolver: Resolvers::Character | |
end | |
# Similarly: | |
class Types::MutationType < GraphQL::Schema::Object | |
# ... | |
end | |
# and | |
class Types::SubscriptionType < GraphQL::Schema::Object | |
# ... | |
end | |
module Types | |
class CharacterType < BaseObject | |
field :first_name, String, null: false | |
field :last_name, String, null: true | |
field :full_name, String, null: false | |
def full_name | |
[object.full_name, object.last_name].join(' ') | |
end | |
end | |
end | |
module Types | |
class CharacterType < BaseObject | |
field :first_name, String, null: false | |
field :last_name, String, null: true | |
field :full_name, String, null: false, resolver: Resolvers::CharacterFullName | |
end | |
end | |
module Resolvers | |
class Character < Resolvers::Base | |
type Character, null: false | |
argument :id, ID, required: true | |
def resolve(id:) | |
Character.find_by_id(id: id) | |
end | |
end | |
end | |
class Types::CharacterAttributes < Types::BaseInputObject | |
argument :first_name, String, required: true | |
argument :last_name, String, required: false | |
argument :role, Types::RoleEnum, required: false | |
end | |
GraphQL.scan(query) | |
[ | |
(QUERY "query" [2:1]), | |
(LCURLY "{" [2:7]), | |
(IDENTIFIER "character" [3:3]), | |
(LCURLY "{" [3:13]), | |
(IDENTIFIER "firstName" [4:5]), | |
(IDENTIFIER "lastName" [5:5]), | |
(IDENTIFIER "friends" [6:5]), | |
(LCURLY "{" [6:13]), | |
(IDENTIFIER "firstName" [7:7]), | |
(IDENTIFIER "lastName" [8:7]), | |
(RCURLY "}" [9:5]), | |
(RCURLY "}" [10:3]), | |
(RCURLY "}" [11:1]) | |
] | |
#<GraphQL::Language::Nodes::Document:0x00007fbd8ae3dec0 | |
@definitions= | |
[#<GraphQL::Language::Nodes::OperationDefinition:0x00007fbd8ae3e0c8 | |
@col=1, | |
@directives=[], | |
@filename=nil, | |
@line=2, | |
@name=nil, | |
@operation_type="query", | |
@selections= | |
[#<GraphQL::Language::Nodes::Field:0x00007fbd8ae3e370 | |
@alias=nil, | |
@arguments=[], | |
@col=3, | |
@directives=[], | |
@filename=nil, | |
@line=3, | |
@name="character", | |
@selections= | |
[#<GraphQL::Language::Nodes::Field:0x00007fbd8ae3ff68 @alias=nil, @arguments=[], @col=5, @directives=[], @filename=nil, @line=4, @name="firstName", @selections=[]>, | |
#<GraphQL::Language::Nodes::Field:0x00007fbd8ae3fbd0 @alias=nil, @arguments=[], @col=5, @directives=[], @filename=nil, @line=5, @name="lastName", @selections=[]>, | |
#<GraphQL::Language::Nodes::Field:0x00007fbd8ae3e5c8 | |
@alias=nil, | |
@arguments=[], | |
@col=5, | |
@directives=[], | |
@filename=nil, | |
@line=6, | |
@name="friends", | |
@selections= | |
[#<GraphQL::Language::Nodes::Field:0x00007fbd8ae3f478 @alias=nil, @arguments=[], @col=7, @directives=[], @filename=nil, @line=7, @name="firstName", @selections=[]>, | |
#<GraphQL::Language::Nodes::Field:0x00007fbd8ae3eeb0 @alias=nil, @arguments=[], @col=7, @directives=[], @filename=nil, @line=8, @name="lastName", @selections=[]>]>]>], | |
@variables=[]>], | |
@filename=nil> | |
#<GraphQL::Language::Nodes::Field:0x00007fbd8ae3eeb0 @alias=nil, @arguments=[], @col=7, @directives=[], @filename=nil, @line=8, @name="lastName", @selections=[]>]>]>], | |
@variables=[]>], | |
@filename=nil> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment