1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
from graphql.type import (
GraphQLArgument,
GraphQLField,
GraphQLInt,
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
)
from gql import Client, gql
static_result = {
"edges": [
{
"node": {
"from": {"address": "0x45b9ad45995577fe"},
"to": {"address": "0x6394e988297f5ed2"},
}
},
{"node": {"from": None, "to": {"address": "0x6394e988297f5ed2"}}},
]
}
def resolve_test(root, _info, count):
return static_result
Account = GraphQLObjectType(
name="Account",
fields={"address": GraphQLField(GraphQLNonNull(GraphQLString))},
)
queryType = GraphQLObjectType(
name="RootQueryType",
fields={
"test": GraphQLField(
GraphQLObjectType(
name="test",
fields={
"edges": GraphQLField(
GraphQLList(
GraphQLObjectType(
"example",
fields={
"node": GraphQLField(
GraphQLObjectType(
name="node",
fields={
"from": GraphQLField(Account),
"to": GraphQLField(Account),
},
)
)
},
)
)
)
},
),
args={"count": GraphQLArgument(GraphQLInt)},
resolve=resolve_test,
),
},
)
schema = GraphQLSchema(query=queryType)
def test_parse_results_null_mapping():
"""This is a regression test for the issue:
https://github.com/graphql-python/gql/issues/325
Most of the parse_results tests are in tests/starwars/test_parse_results.py
"""
client = Client(schema=schema, parse_results=True)
query = gql(
"""query testQ($count: Int) {test(count: $count){
edges {
node {
from {
address
}
to {
address
}
}
}
} }"""
)
query.variable_values = {"count": 2}
assert client.execute(query) == {"test": static_result}
|