Created
February 22, 2024 15:17
-
-
Save rmosolgo/d55f0a96773e8e1dabd91d0b2f2ea6b8 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
require "bundler/inline" | |
gemfile do | |
gem "graphql", "1.12.17" | |
# gem "graphql", "1.12.18" | |
end | |
class MySchema < GraphQL::Schema | |
class Model < GraphQL::Schema::Object | |
field :name, String, null: false | |
end | |
class Make < GraphQL::Schema::Object | |
field :models, Model.connection_type, null: false | |
end | |
class MakeResolver < GraphQL::Schema::Resolver | |
def resolve(name: nil) | |
{ | |
models: [{ name: "Cool car" }] | |
} | |
end | |
end | |
class Query < GraphQL::Schema::Object | |
field :make, Make, null: true, resolver: MakeResolver do # rubocop:disable GraphQL/DefaultNullTrue | |
argument :name, String, required: true # rubocop:disable GraphQL/DefaultRequiredTrue | |
end | |
def make(name:) | |
{ | |
models: [{ name: "Cool car" }] | |
} | |
end | |
end | |
query(Query) | |
end | |
puts GraphQL::VERSION | |
query_str = "query GetModels($name: String) { | |
make(name: $name) { | |
models { | |
edges { | |
node { | |
name | |
} | |
} | |
} | |
} | |
}" | |
pp MySchema.execute(query_str).to_h | |
# 1.12.17 | |
# {"errors"=> | |
# [{"message"=> | |
# "Nullability mismatch on variable $name and argument name (String / String!)", | |
# "locations"=>[{"line"=>2, "column"=>8}], | |
# "path"=>["query GetModels", "make", "name"], | |
# "extensions"=> | |
# {"code"=>"variableMismatch", | |
# "variableName"=>"name", | |
# "typeName"=>"String", | |
# "argumentName"=>"name", | |
# "errorMessage"=>"Nullability mismatch"}}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment