Created
October 9, 2019 17:55
-
-
Save dmaze/c93ec7aa36ee0b17df2ded223e3b5ac8 to your computer and use it in GitHub Desktop.
graphql-ruby 1.9.8 resolver arguments don't work when schema is built from_definition
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
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
# This illustrates a bug in graphql-ruby 1.9.8. Prior to this version, | |
# a resolver function passed in the map to GraphQL::Schema.from_definition | |
# could access its arguments as methods on the `args` object it gets passed; | |
# but starting in graphql-ruby 1.9.8 this no longer works. | |
require 'graphql' | |
# This is a sample very small GraphQL schema. | |
SDL = <<~GRAPHQL | |
input In { s: String! } | |
type Query { | |
echo(in: In!): String! | |
} | |
GRAPHQL | |
RESOLVERS = { | |
'Query' => { | |
# vvv THIS LINE is what breaks | |
'echo' => ->(_obj, args, _ctx) { args.in.s } | |
# ^^^ | |
# | |
# In graphql-ruby 1.9.7, args.in.s resolves to the passed-in | |
# argument. In graphql-ruby 1.9.8, it produces a NoMethodError | |
# where args.in isn't defined. | |
}.freeze | |
}.freeze | |
# Create the GraphQL schema object | |
Schema = GraphQL::Schema.from_definition(SDL, default_resolve: RESOLVERS) | |
# Run a minimal query | |
QUERY = '{ echo(in: { s: "foo" }) }' | |
result = Schema.execute(QUERY) | |
p result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment