Skip to content

Commit 4193ace

Browse files
committed
Added query, mutate and execute method to dsl
1 parent 13fa71f commit 4193ace

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

gql/dsl.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ def __getattr__(self, name):
2323
type_def = self.schema.get_type(name)
2424
return DSLType(type_def)
2525

26+
def query(self, *args, **kwargs):
27+
return self.execute(query(*args, **kwargs))
28+
29+
def mutate(self, *args, **kwargs):
30+
return self.query(*args, operation='mutate', **kwargs)
31+
32+
def execute(self, document):
33+
return self.client.execute(document)
34+
2635

2736
class DSLType(object):
2837
def __init__(self, type):

tests/starwars/test_dsl.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,18 @@ def test_fetch_luke_aliased(ds):
277277
# result = schema.execute(query)
278278
# assert not result.errors
279279
# assert result.data == expected
280+
281+
282+
283+
def test_hero_name_query(ds):
284+
result = ds.query(
285+
ds.Query.hero.select(
286+
ds.Character.name
287+
)
288+
)
289+
expected = {
290+
'hero': {
291+
'name': 'R2-D2'
292+
}
293+
}
294+
assert result == expected

0 commit comments

Comments
 (0)