Skip to content

Commit

Permalink
Fix fragments on types from non-default module.
Browse files Browse the repository at this point in the history
Using types from non-default module in fragments no longer causes
unresolved type error.

Issue #5985 (b)
  • Loading branch information
vpetrovykh authored and msullivan committed Sep 27, 2023
1 parent 6d5d78a commit ef38c80
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 18 deletions.
8 changes: 8 additions & 0 deletions edb/graphql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,11 +1428,19 @@ def get(self, name: str, *, dummy: bool = False) -> GQLBaseType:

for tname in names:
if edb_base is None:
module: Union[s_name.Name, str]

if '::' in tname:
edb_base = self.edb_schema.get(
tname,
type=s_types.Type,
)
elif '__' in tname:
# Looks like it's coming from a specific module
edb_base = self.edb_schema.get(
f"{tname.replace('__', '::')}",
type=s_types.Type,
)
else:
for module in self.modules:
edb_base = self.edb_schema.get(
Expand Down
112 changes: 94 additions & 18 deletions tests/test_http_graphql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ def test_graphql_functional_fragment_05(self):
}],
})

def test_graphql_functional_fragment_type_01(self):
def test_graphql_functional_fragment_06(self):
self.assert_graphql_query_result(r"""
fragment userFrag on User {
id,
Expand All @@ -1817,7 +1817,7 @@ def test_graphql_functional_fragment_type_01(self):
}],
})

def test_graphql_functional_fragment_type_02(self):
def test_graphql_functional_fragment_07(self):
self.assert_graphql_query_result(r"""
fragment namedFrag on NamedObject {
id,
Expand All @@ -1836,7 +1836,7 @@ def test_graphql_functional_fragment_type_02(self):
}],
})

def test_graphql_functional_fragment_type_03(self):
def test_graphql_functional_fragment_08(self):
self.assert_graphql_query_result(r"""
fragment namedFrag on NamedObject {
id,
Expand All @@ -1861,7 +1861,7 @@ def test_graphql_functional_fragment_type_03(self):
}],
})

def test_graphql_functional_fragment_type_04(self):
def test_graphql_functional_fragment_09(self):
with self.assertRaisesRegex(
edgedb.QueryError,
r"Fragment 'userFrag' cannot be spread here "
Expand All @@ -1880,7 +1880,7 @@ def test_graphql_functional_fragment_type_04(self):
}
""")

def test_graphql_functional_fragment_type_05(self):
def test_graphql_functional_fragment_10(self):
with self.assertRaisesRegex(
edgedb.QueryError,
r"Fragment 'userFrag' cannot be spread here "
Expand All @@ -1906,7 +1906,7 @@ def test_graphql_functional_fragment_type_05(self):
}
""")

def test_graphql_functional_fragment_type_06(self):
def test_graphql_functional_fragment_11(self):
self.assert_graphql_query_result(r"""
fragment userFrag on User {
age
Expand Down Expand Up @@ -1940,7 +1940,7 @@ def test_graphql_functional_fragment_type_06(self):
]
}, sort=lambda x: x['name'])

def test_graphql_functional_fragment_type_07(self):
def test_graphql_functional_fragment_12(self):
self.assert_graphql_query_result(r"""
fragment frag on NamedObject {
id,
Expand Down Expand Up @@ -1973,7 +1973,7 @@ def test_graphql_functional_fragment_type_07(self):
]
}, sort=lambda x: x['name'])

def test_graphql_functional_fragment_type_08(self):
def test_graphql_functional_fragment_13(self):
with self.assertRaisesRegex(
edgedb.QueryError,
"Cannot query field 'age' on type 'NamedObject'",
Expand All @@ -1992,7 +1992,7 @@ def test_graphql_functional_fragment_type_08(self):
}
""")

def test_graphql_functional_fragment_type_09(self):
def test_graphql_functional_fragment_14(self):
with self.assertRaisesRegex(
edgedb.QueryError,
"Cannot query field 'age' on type 'NamedObject'",
Expand All @@ -2009,7 +2009,7 @@ def test_graphql_functional_fragment_type_09(self):
}
""")

def test_graphql_functional_fragment_type_10(self):
def test_graphql_functional_fragment_15(self):
self.assert_graphql_query_result(r"""
fragment namedFrag on NamedObject {
id,
Expand Down Expand Up @@ -2047,7 +2047,7 @@ def test_graphql_functional_fragment_type_10(self):
]
}, sort=lambda x: x['name'])

def test_graphql_functional_fragment_type_11(self):
def test_graphql_functional_fragment_16(self):
self.assert_graphql_query_result(r"""
fragment namedFrag on NamedObject {
id,
Expand Down Expand Up @@ -2077,7 +2077,7 @@ def test_graphql_functional_fragment_type_11(self):
"Known collation issue on Heroku Postgres",
unless=os.getenv("EDGEDB_TEST_BACKEND_VENDOR") != "heroku-postgres"
)
def test_graphql_functional_fragment_type_12(self):
def test_graphql_functional_fragment_17(self):
self.assert_graphql_query_result(r"""
query {
NamedObject(order: {name: {dir: ASC}}) {
Expand Down Expand Up @@ -2107,7 +2107,7 @@ def test_graphql_functional_fragment_type_12(self):
]
})

def test_graphql_functional_fragment_type_13(self):
def test_graphql_functional_fragment_18(self):
# ISSUE #1800
#
# After using a typed inline fragment the nested fields or
Expand Down Expand Up @@ -2135,7 +2135,7 @@ def test_graphql_functional_fragment_type_13(self):
}],
})

def test_graphql_functional_fragment_type_14(self):
def test_graphql_functional_fragment_19(self):
# ISSUE #1800
#
# After using a typed inline fragment the nested fields or
Expand Down Expand Up @@ -2165,7 +2165,7 @@ def test_graphql_functional_fragment_type_14(self):
}],
})

def test_graphql_functional_fragment_type_15(self):
def test_graphql_functional_fragment_20(self):
# ISSUE #1800
#
# After using a typed inline fragment the nested fields or
Expand Down Expand Up @@ -2213,7 +2213,7 @@ def test_graphql_functional_fragment_type_15(self):
}],
})

def test_graphql_functional_fragment_type_16(self):
def test_graphql_functional_fragment_21(self):
# ISSUE #1800
#
# After using a typed inline fragment the nested fields or
Expand Down Expand Up @@ -2265,7 +2265,7 @@ def test_graphql_functional_fragment_type_16(self):
}],
})

def test_graphql_functional_fragment_type_17(self):
def test_graphql_functional_fragment_22(self):
# ISSUE #1800
#
# After using a typed inline fragment the nested fields or
Expand Down Expand Up @@ -2295,7 +2295,7 @@ def test_graphql_functional_fragment_type_17(self):
}],
})

def test_graphql_functional_fragment_type_18(self):
def test_graphql_functional_fragment_23(self):
# ISSUE #3514
#
# Fragment on the actual type should also work.
Expand All @@ -2321,6 +2321,82 @@ def test_graphql_functional_fragment_type_18(self):
}],
})

def test_graphql_functional_fragment_24(self):
# ISSUE #5985
#
# Types from non-default module should be recognized in fragments.
self.assert_graphql_query_result(r"""
fragment myFrag on other__Foo {
id,
color,
}
query {
other__Foo(filter: {color: {eq: RED}}) {
... myFrag
}
}
""", {
'other__Foo': [{
'id': uuid.UUID,
'color': 'RED',
}],
})

self.assert_graphql_query_result(r"""
fragment myFrag on other__Foo_Type {
id,
color,
}
query {
other__Foo(filter: {color: {eq: RED}}) {
... myFrag
}
}
""", {
'other__Foo': [{
'id': uuid.UUID,
'color': 'RED',
}],
})

def test_graphql_functional_fragment_25(self):
# ISSUE #5985
#
# Types from non-default module should be recognized in fragments.
self.assert_graphql_query_result(r"""
query {
other__Foo(filter: {color: {eq: RED}}) {
... on other__Foo {
id,
color,
}
}
}
""", {
'other__Foo': [{
'id': uuid.UUID,
'color': 'RED',
}],
})

self.assert_graphql_query_result(r"""
query {
other__Foo(filter: {color: {eq: RED}}) {
... on other__Foo_Type {
id,
color,
}
}
}
""", {
'other__Foo': [{
'id': uuid.UUID,
'color': 'RED',
}],
})

def test_graphql_functional_directives_01(self):
self.assert_graphql_query_result(r"""
query {
Expand Down

0 comments on commit ef38c80

Please sign in to comment.