This file contains hidden or 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
interface Node { | |
id: ID! | |
} | |
interface Person { | |
firstName: String! | |
lastName: String | |
} | |
type Character implements Node & Person { |
This file contains hidden or 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 Types::ResultType < Types::BaseUnion | |
possible_types Types::CharacterType, Types::LandType, Types::BuildingType | |
# Optional: if this method is defined, it will override `Schema.resolve_type` | |
def self.resolve_type(object, context) | |
if object.is_a?(Character) | |
Types::CharacterType | |
elsif object.is_a?(Land) | |
Types::LandType | |
else |
This file contains hidden or 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
{ | |
"data": { | |
"search": [ | |
{ | |
"__typename": "Character", | |
"firstName": "Finn" | |
}, | |
{ | |
"__typename": "Land", | |
"name": "Land of Ooo" |
This file contains hidden or 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
{ | |
search(in: "Adventure Time") { | |
__typename | |
... on Character { | |
firstName | |
} | |
... on land { | |
name | |
} | |
... on Building { |
This file contains hidden or 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
union Result = Character | Land | Building | |
type Character { | |
firstName: String! | |
} | |
type Building { | |
type: String! | |
} |
This file contains hidden or 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 Types::RoleEnum < Types::BaseEnum | |
value 'FATHER', value: :father | |
value 'MOTHER', value: :mom | |
value 'SON', value: :son | |
value 'DAUGHTER', value: :daughter | |
value 'PET', value: :animal | |
end |
This file contains hidden or 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
enum RoleEnum { | |
FATHER | |
MOTHER | |
SON | |
DAUGHTER | |
DOG | |
} |
This file contains hidden or 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 Types::Url < Types::BaseScalar | |
description "A valid URL, transported as a string" | |
def self.coerce_input(input_value, context) | |
url = URI.parse(input_value) | |
if url.is_a?(URI::HTTP) || url.is_a?(URI::HTTPS) | |
url | |
else | |
raise GraphQL::CoercionError, "#{input_value.inspect} is not a valid URL" | |
end |
This file contains hidden or 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
module Types | |
class CharacterType < BaseObject | |
field :first_name, String, null: false | |
field :last_name, String, null: true do | |
argument :reverse, Boolean, required: false | |
end | |
field :friends, [Types::CharacterType], null: true do | |
argument :last, Integer, required: false | |
end | |
end |
This file contains hidden or 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
module Types | |
class CharacterType < BaseObject | |
field :first_name, String, null: false | |
field :last_name, String, null: true | |
field :friends, [Types::CharacterType], null: true | |
end | |
end |