Skip to content

Commit

Permalink
Added query, mutate and execute method to dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Dec 19, 2016
1 parent 13fa71f commit 4193ace
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gql/dsl.py
Expand Up @@ -23,6 +23,15 @@ def __getattr__(self, name):
type_def = self.schema.get_type(name)
return DSLType(type_def)

def query(self, *args, **kwargs):
return self.execute(query(*args, **kwargs))

def mutate(self, *args, **kwargs):
return self.query(*args, operation='mutate', **kwargs)

def execute(self, document):
return self.client.execute(document)


class DSLType(object):
def __init__(self, type):
Expand Down
15 changes: 15 additions & 0 deletions tests/starwars/test_dsl.py
Expand Up @@ -277,3 +277,18 @@ def test_fetch_luke_aliased(ds):
# result = schema.execute(query)
# assert not result.errors
# assert result.data == expected



def test_hero_name_query(ds):
result = ds.query(
ds.Query.hero.select(
ds.Character.name
)
)
expected = {
'hero': {
'name': 'R2-D2'
}
}
assert result == expected

0 comments on commit 4193ace

Please sign in to comment.