diff --git a/lib/graphql/introspection/entry_points.rb b/lib/graphql/introspection/entry_points.rb index 52d89eed86..82ca149001 100644 --- a/lib/graphql/introspection/entry_points.rb +++ b/lib/graphql/introspection/entry_points.rb @@ -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 diff --git a/lib/graphql/introspection/type_type.rb b/lib/graphql/introspection/type_type.rb index 583b87be0d..493d2b8d0c 100644 --- a/lib/graphql/introspection/type_type.rb +++ b/lib/graphql/introspection/type_type.rb @@ -49,7 +49,7 @@ 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 @@ -57,7 +57,7 @@ def interfaces def input_fields if @object.kind.input_object? - @context.warden.arguments(@object) + @context.warden.arguments(@object.graphql_definition) else nil end @@ -65,7 +65,7 @@ def input_fields def possible_types if @object.kind.abstract? - @context.warden.possible_types(@object) + @context.warden.possible_types(@object.graphql_definition) else nil end @@ -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 diff --git a/spec/graphql/schema/input_object_spec.rb b/spec/graphql/schema/input_object_spec.rb index c7929ae2cc..a5aea99fbc 100644 --- a/spec/graphql/schema/input_object_spec.rb +++ b/spec/graphql/schema/input_object_spec.rb @@ -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