Skip to content

Commit

Permalink
Merge pull request #2006 from rmosolgo/fix-input-fields
Browse files Browse the repository at this point in the history
Fix introspection on interpreter
  • Loading branch information
Robert Mosolgo authored Dec 13, 2018
2 parents 04e168c + 5cab5ca commit 06144cb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/graphql/introspection/entry_points.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ def __schema
end

def __type(name:)
# This will probably break with non-Interpreter runtime
type = context.warden.get_type(name)

if type && context.interpreter?
type = type.metadata[:type_class] || raise("Invariant: interpreter requires class-based type for #{name}")
end

# The interpreter provides this wrapping, other execution doesnt, so support both.
if type && !context.interpreter?
# Apply wrapping manually since this field isn't wrapped by instrumentation
Expand Down
8 changes: 4 additions & 4 deletions lib/graphql/introspection/type_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ def enum_values(include_deprecated:)

def interfaces
if @object.kind == GraphQL::TypeKinds::OBJECT
@context.warden.interfaces(@object)
@context.warden.interfaces(@object.graphql_definition)
else
nil
end
end

def input_fields
if @object.kind.input_object?
@context.warden.arguments(@object)
@context.warden.arguments(@object.graphql_definition)
else
nil
end
end

def possible_types
if @object.kind.abstract?
@context.warden.possible_types(@object)
@context.warden.possible_types(@object.graphql_definition)
else
nil
end
Expand All @@ -75,7 +75,7 @@ def fields(include_deprecated:)
if !@object.kind.fields?
nil
else
fields = @context.warden.fields(@object)
fields = @context.warden.fields(@object.graphql_definition)
if !include_deprecated
fields = fields.select {|f| !f.deprecation_reason }
end
Expand Down
23 changes: 23 additions & 0 deletions spec/graphql/schema/input_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,29 @@ class TestInput2 < GraphQL::Schema::InputObject
# assert_equal 3, input_object.dig('input_object', 'd')
assert_equal 3, input_object.dig(:input_object, :d)
end
end

describe "introspection" do
it "returns input fields" do
res = Jazz::Schema.execute('
{
__type(name: "InspectableInput") {
name
inputFields { name }
}
__schema {
types {
name
inputFields { name }
}
}
}')
# Test __type
assert_equal ["stringValue", "nestedInput", "legacyInput"], res["data"]["__type"]["inputFields"].map { |f| f["name"] }
# Test __schema { types }
# It's upcased to test custom introspection
input_type = res["data"]["__schema"]["types"].find { |t| t["name"] == "INSPECTABLEINPUT" }
assert_equal ["stringValue", "nestedInput", "legacyInput"], input_type["inputFields"].map { |f| f["name"] }
end
end
end

0 comments on commit 06144cb

Please sign in to comment.