def concats_two_acts_together(): source_a = Source(""" { a, b, ... Frag } """) source_b = Source(""" fragment Frag on T { c } """) ast_a = parse(source_a) ast_b = parse(source_b) ast_c = concat_ast([ast_a, ast_b]) assert print_ast(ast_c) == dedent(""" { a b ...Frag } fragment Frag on T { c } """)
def correctly_assigns_ast_nodes_to_new_and_extended_types(): schema = build_schema(""" type Query scalar SomeScalar enum SomeEnum union SomeUnion input SomeInput type SomeObject interface SomeInterface directive @foo on SCALAR """) first_extension_ast = parse(""" extend type Query { newField(testArg: TestInput): TestEnum } extend scalar SomeScalar @foo extend enum SomeEnum { NEW_VALUE } extend union SomeUnion = SomeObject extend input SomeInput { newField: String } extend interface SomeInterface { newField: String } enum TestEnum { TEST_VALUE } input TestInput { testInputField: TestEnum } """) extended_schema = extend_schema(schema, first_extension_ast) second_extension_ast = parse(""" extend type Query { oneMoreNewField: TestUnion } extend scalar SomeScalar @test extend enum SomeEnum { ONE_MORE_NEW_VALUE } extend union SomeUnion = TestType extend input SomeInput { oneMoreNewField: String } extend interface SomeInterface { oneMoreNewField: String } union TestUnion = TestType interface TestInterface { interfaceField: String } type TestType implements TestInterface { interfaceField: String } directive @test(arg: Int) repeatable on FIELD | SCALAR """) extended_twice_schema = extend_schema(extended_schema, second_extension_ast) extend_in_one_go_schema = extend_schema( schema, concat_ast([first_extension_ast, second_extension_ast])) assert print_schema(extend_in_one_go_schema) == print_schema( extended_twice_schema) query = assert_object_type(extended_twice_schema.get_type("Query")) some_enum = assert_enum_type( extended_twice_schema.get_type("SomeEnum")) some_union = assert_union_type( extended_twice_schema.get_type("SomeUnion")) some_scalar = assert_scalar_type( extended_twice_schema.get_type("SomeScalar")) some_input = assert_input_object_type( extended_twice_schema.get_type("SomeInput")) some_interface = assert_interface_type( extended_twice_schema.get_type("SomeInterface")) test_input = assert_input_object_type( extended_twice_schema.get_type("TestInput")) test_enum = assert_enum_type( extended_twice_schema.get_type("TestEnum")) test_union = assert_union_type( extended_twice_schema.get_type("TestUnion")) test_type = assert_object_type( extended_twice_schema.get_type("TestType")) test_interface = assert_interface_type( extended_twice_schema.get_type("TestInterface")) test_directive = assert_directive( extended_twice_schema.get_directive("test")) assert test_type.extension_ast_nodes is None assert test_enum.extension_ast_nodes is None assert test_union.extension_ast_nodes is None assert test_input.extension_ast_nodes is None assert test_interface.extension_ast_nodes is None assert query.extension_ast_nodes assert len(query.extension_ast_nodes) == 2 assert some_scalar.extension_ast_nodes assert len(some_scalar.extension_ast_nodes) == 2 assert some_enum.extension_ast_nodes assert len(some_enum.extension_ast_nodes) == 2 assert some_union.extension_ast_nodes assert len(some_union.extension_ast_nodes) == 2 assert some_input.extension_ast_nodes assert len(some_input.extension_ast_nodes) == 2 assert some_interface.extension_ast_nodes assert len(some_interface.extension_ast_nodes) == 2 assert { test_input.ast_node, test_enum.ast_node, test_union.ast_node, test_interface.ast_node, test_type.ast_node, test_directive.ast_node, *query.extension_ast_nodes, *some_scalar.extension_ast_nodes, *some_enum.extension_ast_nodes, *some_union.extension_ast_nodes, *some_input.extension_ast_nodes, *some_interface.extension_ast_nodes, } == { *first_extension_ast.definitions, *second_extension_ast.definitions } new_field = query.fields["newField"] assert print_ast_node( new_field) == "newField(testArg: TestInput): TestEnum" assert print_ast_node( new_field.args["testArg"]) == "testArg: TestInput" assert (print_ast_node( query.fields["oneMoreNewField"]) == "oneMoreNewField: TestUnion") new_value = some_enum.values["NEW_VALUE"] assert print_ast_node(new_value) == "NEW_VALUE" one_more_new_value = some_enum.values["ONE_MORE_NEW_VALUE"] assert print_ast_node(one_more_new_value) == "ONE_MORE_NEW_VALUE" assert print_ast_node( some_input.fields["newField"]) == "newField: String" assert (print_ast_node( some_input.fields["oneMoreNewField"]) == "oneMoreNewField: String") assert print_ast_node( some_interface.fields["newField"]) == "newField: String" assert (print_ast_node(some_interface.fields["oneMoreNewField"]) == "oneMoreNewField: String") assert (print_ast_node( test_input.fields["testInputField"]) == "testInputField: TestEnum") test_value = test_enum.values["TEST_VALUE"] assert print_ast_node(test_value) == "TEST_VALUE" assert (print_ast_node(test_interface.fields["interfaceField"]) == "interfaceField: String") assert (print_ast_node( test_type.fields["interfaceField"]) == "interfaceField: String") assert print_ast_node(test_directive.args["arg"]) == "arg: Int"