Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix introspection on interpreter #2006

Merged
merged 2 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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