Skip to content

Commit b680e46

Browse files
committed
Update the tests and examples to use the latest graphene api
1 parent 58b95bb commit b680e46

File tree

3 files changed

+58
-84
lines changed

3 files changed

+58
-84
lines changed

examples/departments.py

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -103,37 +103,32 @@ def resolve_list_departments(self, info):
103103

104104

105105
if __name__ == "__main__":
106-
from graphql.execution.executors.sync import SyncExecutor
107-
108106
schema = graphene.Schema(query=Query)
109-
result = schema.execute(
110-
"""
111-
query {
112-
listDepartments {
113-
id,
114-
name,
115-
employees {
116-
...on Employee {
117-
id
118-
name
119-
hiredOn
120-
salary { rating }
121-
}
122-
...on Manager {
123-
name
124-
salary {
125-
rating
126-
amount
127-
}
128-
teamSize
107+
query = """
108+
query {
109+
listDepartments {
110+
id,
111+
name,
112+
employees {
113+
...on Employee {
114+
id
115+
name
116+
hiredOn
117+
salary { rating }
118+
}
119+
...on Manager {
120+
name
121+
salary {
122+
rating
123+
amount
124+
}
125+
teamSize
126+
}
129127
}
130-
}
131128
}
132-
}
133-
""",
134-
executor=SyncExecutor(),
135-
return_promise=False,
136-
)
129+
}
130+
"""
131+
result = schema.execute(query)
137132

138133
print(result.errors)
139134
print(json.dumps(result.data, indent=2))

tests/test_forward_refs.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,34 +77,29 @@ def resolve_list_foos(self, info):
7777

7878

7979
def test_query():
80-
from graphql.execution.executors.sync import SyncExecutor
81-
8280
schema = graphene.Schema(query=Query)
83-
result = schema.execute(
84-
"""
85-
query {
86-
listFoos {
87-
id
88-
name
89-
bar {
90-
id
91-
name
92-
foo {
93-
id
94-
baz {
81+
query = """
82+
query {
83+
listFoos {
84+
id
9585
name
96-
bar { id }
97-
}
86+
bar {
87+
id
88+
name
89+
foo {
90+
id
91+
baz {
92+
name
93+
bar { id }
94+
}
95+
}
96+
}
97+
baz { name }
98+
someBars { id }
9899
}
99-
}
100-
baz { name }
101-
someBars { id }
102100
}
103-
}
104-
""",
105-
executor=SyncExecutor(),
106-
return_promise=False,
107-
)
101+
"""
102+
result = schema.execute(query)
108103

109104
assert result.errors is None
110105
assert result.data is not None

tests/test_graphene.py

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,76 +59,60 @@ class Mutation(graphene.ObjectType):
5959

6060

6161
def test_query():
62-
from graphql.execution.executors.sync import SyncExecutor
63-
6462
global foo_bars
6563
foo_bars = [FooBar(name="test", count=1)]
6664

6765
schema = graphene.Schema(query=Query)
68-
result = schema.execute(
69-
"""
66+
query = """
7067
query {
7168
listFooBars {
72-
name
73-
count
69+
name
70+
count
7471
}
7572
}
76-
""",
77-
executor=SyncExecutor(),
78-
return_promise=False,
79-
)
73+
"""
74+
result = schema.execute(query)
8075

8176
assert result.errors is None
8277
assert result.data is not None
8378
assert pydantic.parse_obj_as(List[FooBar], result.data["listFooBars"]) == foo_bars
8479

8580

8681
def test_query_with_match():
87-
from graphql.execution.executors.sync import SyncExecutor
88-
8982
global foo_bars
9083
foo_bars = [FooBar(name="test", count=1)]
9184

9285
schema = graphene.Schema(query=Query)
93-
result = schema.execute(
94-
"""
86+
query = """
9587
query {
9688
listFooBars(match: {name: "test", count: 1}) {
97-
name
98-
count
89+
name
90+
count
9991
}
10092
}
101-
""",
102-
executor=SyncExecutor(),
103-
return_promise=False,
104-
)
93+
"""
94+
result = schema.execute(query)
10595

10696
assert result.errors is None
10797
assert result.data is not None
10898
assert pydantic.parse_obj_as(List[FooBar], result.data["listFooBars"]) == foo_bars
10999

110100

111101
def test_mutation():
112-
from graphql.execution.executors.sync import SyncExecutor
113-
114102
global foo_bars
115103
foo_bars = []
116104

117-
schema = graphene.Schema(mutation=Mutation)
105+
schema = graphene.Schema(query=Query, mutation=Mutation)
118106
new_foo_bar = FooBar(name="mutant", count=-1)
119-
result = schema.execute(
120-
"""
107+
query = """
121108
mutation {
122109
createFooBar(data: {name: "%s", count: %d}) {
123-
name
124-
count
110+
name
111+
count
125112
}
126113
}
127-
"""
128-
% (new_foo_bar.name, new_foo_bar.count),
129-
executor=SyncExecutor(),
130-
return_promise=False,
131-
)
114+
""" % (new_foo_bar.name, new_foo_bar.count)
115+
result = schema.execute(query)
132116

133117
assert result.errors is None
134118
assert result.data is not None

0 commit comments

Comments
 (0)