Skip to content

Commit 9aed997

Browse files
authored
Merge pull request #138 from mwilliamson-healx/recursive-input-types
Support recursive input object types in build_ast_schema
2 parents 0d4f952 + 1feb4b2 commit 9aed997

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

graphql/utils/build_ast_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def make_scalar_def(definition):
234234
def make_input_object_def(definition):
235235
return GraphQLInputObjectType(
236236
name=definition.name.value,
237-
fields=make_input_values(definition.fields, GraphQLInputObjectField)
237+
fields=lambda: make_input_values(definition.fields, GraphQLInputObjectField)
238238
)
239239

240240
_schema_def_handlers = {

graphql/utils/tests/test_build_ast_schema.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pytest import raises
22

3-
from graphql import parse
3+
from graphql import GraphQLInt, parse
44
from graphql.utils.build_ast_schema import build_ast_schema
55
from graphql.utils.schema_printer import print_schema
66

@@ -392,6 +392,44 @@ def test_input_object():
392392
assert output == body
393393

394394

395+
def test_input_types_are_read():
396+
schema = build_ast_schema(parse("""
397+
schema {
398+
query: Query
399+
}
400+
401+
type Query {
402+
field(input: Input): Int
403+
}
404+
405+
input Input {
406+
id: Int
407+
}
408+
"""))
409+
410+
input_type = schema.get_type("Input")
411+
assert input_type.fields["id"].type == GraphQLInt
412+
413+
414+
def test_input_types_can_be_recursive():
415+
schema = build_ast_schema(parse("""
416+
schema {
417+
query: Query
418+
}
419+
420+
type Query {
421+
field(input: Input): Int
422+
}
423+
424+
input Input {
425+
id: Input
426+
}
427+
"""))
428+
429+
input_type = schema.get_type("Input")
430+
assert input_type.fields["id"].type == input_type
431+
432+
395433
def test_simple_argument_field_with_default():
396434
body = '''
397435
schema {

0 commit comments

Comments
 (0)