diff --git a/edb/graphql/types.py b/edb/graphql/types.py index 2047fa7bdbc..3d7cac92bb1 100644 --- a/edb/graphql/types.py +++ b/edb/graphql/types.py @@ -2045,20 +2045,24 @@ def get_field_type(self, name: str) -> Optional[GQLBaseType]: fkey = (name, self.dummy) target = None - op, name = name.split('_', 1) - if op in {'delete', 'insert', 'update'}: + if name == '__typename': + # It's a valid field that doesn't start with a command target = super().get_field_type(name) + else: + op, name = name.split('_', 1) + if op in {'delete', 'insert', 'update'}: + target = super().get_field_type(name) - if target is None: - module, edb_name = self.get_module_and_name(name) - edb_qname = s_name.QualName(module=module, name=edb_name) - edb_type = self.edb_schema.get( - edb_qname, - default=None, - type=s_types.Type, - ) - if edb_type is not None: - target = self.convert_edb_to_gql_type(edb_type) + if target is None: + module, edb_name = self.get_module_and_name(name) + edb_qname = s_name.QualName(module=module, name=edb_name) + edb_type = self.edb_schema.get( + edb_qname, + default=None, + type=s_types.Type, + ) + if edb_type is not None: + target = self.convert_edb_to_gql_type(edb_type) if target is not None: self._fields[fkey] = target diff --git a/tests/test_http_graphql_mutation.py b/tests/test_http_graphql_mutation.py index f1924aa528f..8276ba3d09c 100644 --- a/tests/test_http_graphql_mutation.py +++ b/tests/test_http_graphql_mutation.py @@ -2174,6 +2174,71 @@ def test_graphql_mutation_insert_readonly_02(self): "Fixed": [data] }) + def test_graphql_mutation_insert_typename_01(self): + # This tests the typename funcitonality after insertion. + # Issue #5985 + data = { + '__typename': 'other__Foo_Type', + 'select': 'New TypenameTest01', + 'color': 'GREEN', + } + + validation_query = r""" + query { + __typename + other__Foo(filter: {select: {eq: "New TypenameTest01"}}) { + __typename + select + color + } + } + """ + + self.assert_graphql_query_result(r""" + mutation insert_other__Foo { + __typename + insert_other__Foo( + data: [{ + select: "New TypenameTest01", + color: GREEN, + }] + ) { + __typename + select + color + } + } + """, { + "__typename": 'Mutation', + "insert_other__Foo": [data] + }) + + self.assert_graphql_query_result(validation_query, { + "__typename": 'Query', + "other__Foo": [data] + }) + + self.assert_graphql_query_result(r""" + mutation delete_other__Foo { + __typename + delete_other__Foo( + filter: {select: {eq: "New TypenameTest01"}} + ) { + __typename + select + color + } + } + """, { + "__typename": 'Mutation', + "delete_other__Foo": [data] + }) + + # validate that the deletion worked + self.assert_graphql_query_result(validation_query, { + "other__Foo": [] + }) + def test_graphql_mutation_update_scalars_01(self): orig_data = { 'p_bool': True, @@ -4813,6 +4878,77 @@ def test_graphql_mutation_update_multiple_03(self): }] }) + def test_graphql_mutation_update_typename_01(self): + # This tests the typename funcitonality after insertion. + # Issue #5985 + + self.assert_graphql_query_result(r""" + mutation insert_other__Foo { + __typename + insert_other__Foo( + data: [{ + select: "Update TypenameTest01", + color: BLUE + }] + ) { + __typename + select + color + } + } + """, { + "__typename": 'Mutation', + "insert_other__Foo": [{ + '__typename': 'other__Foo_Type', + 'select': 'Update TypenameTest01', + 'color': 'BLUE', + }] + }) + + self.assert_graphql_query_result(r""" + mutation update_other__Foo { + __typename + update_other__Foo( + filter: {select: {eq: "Update TypenameTest01"}} + data: { + color: {set: RED} + } + ) { + __typename + select + color + } + } + """, { + "__typename": 'Mutation', + "update_other__Foo": [{ + '__typename': 'other__Foo_Type', + 'select': 'Update TypenameTest01', + 'color': 'RED', + }] + }) + + # clean up + self.assert_graphql_query_result(r""" + mutation delete_other__Foo { + __typename + delete_other__Foo( + filter: {select: {eq: "Update TypenameTest01"}} + ) { + __typename + select + color + } + } + """, { + "__typename": 'Mutation', + "delete_other__Foo": [{ + '__typename': 'other__Foo_Type', + 'select': 'Update TypenameTest01', + 'color': 'RED', + }] + }) + def test_graphql_mutation_delete_alias_01(self): self.assert_graphql_query_result(r""" mutation insert_Setting {