Skip to content

Commit 13fa71f

Browse files
committed
Improved DSL selection queries
1 parent 269d2e9 commit 13fa71f

File tree

2 files changed

+10
-31
lines changed

2 files changed

+10
-31
lines changed

gql/dsl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ def __init__(self, name, field):
7070
self.ast_field = ast.Field(name=ast.Name(value=name), arguments=[])
7171
self.selection_set = None
7272

73-
def get(self, *fields):
73+
def select(self, *fields):
7474
if not self.ast_field.selection_set:
7575
self.ast_field.selection_set = ast.SelectionSet(selections=[])
7676
self.ast_field.selection_set.selections.extend(selections(*fields))
7777
return self
7878

7979
def __call__(self, *args, **kwargs):
80-
return self.get(*args, **kwargs)
80+
return self.args(*args, **kwargs)
8181

8282
def alias(self, alias):
8383
self.ast_field.alias = ast.Name(value=alias)

tests/starwars/test_dsl.py

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,6 @@
33
from gql import Client
44
from gql.dsl import DSLSchema
55

6-
from .schema import characterInterface, humanType, queryType
7-
8-
9-
# We construct a Simple DSL objects for easy field referencing
10-
11-
# class Query(object):
12-
# hero = queryType.fields['hero']
13-
# human = queryType.fields['human']
14-
15-
16-
# class Character(object):
17-
# id = characterInterface.fields['id']
18-
# name = characterInterface.fields['name']
19-
# friends = characterInterface.fields['friends']
20-
# appears_in = characterInterface.fields['appearsIn']
21-
22-
23-
# class Human(object):
24-
# name = humanType.fields['name']
25-
26-
276
from .schema import StarWarsSchema
287

298

@@ -40,7 +19,7 @@ def test_hero_name_query(ds):
4019
name
4120
}
4221
'''.strip()
43-
query_dsl = ds.Query.hero(
22+
query_dsl = ds.Query.hero.select(
4423
ds.Character.name
4524
)
4625
assert query == str(query_dsl)
@@ -56,10 +35,10 @@ def test_hero_name_and_friends_query(ds):
5635
}
5736
}
5837
'''.strip()
59-
query_dsl = ds.Query.hero(
38+
query_dsl = ds.Query.hero.select(
6039
ds.Character.id,
6140
ds.Character.name,
62-
ds.Character.friends(
41+
ds.Character.friends.select(
6342
ds.Character.name,
6443
)
6544
)
@@ -79,12 +58,12 @@ def test_nested_query(ds):
7958
}
8059
}
8160
'''.strip()
82-
query_dsl = ds.Query.hero(
61+
query_dsl = ds.Query.hero.select(
8362
ds.Character.name,
84-
ds.Character.friends(
63+
ds.Character.friends.select(
8564
ds.Character.name,
8665
ds.Character.appears_in,
87-
ds.Character.friends(
66+
ds.Character.friends.select(
8867
ds.Character.name
8968
)
9069
)
@@ -98,7 +77,7 @@ def test_fetch_luke_query(ds):
9877
name
9978
}
10079
'''.strip()
101-
query_dsl = ds.Query.human.args(id="1000").get(
80+
query_dsl = ds.Query.human(id="1000").select(
10281
ds.Human.name,
10382
)
10483

@@ -172,7 +151,7 @@ def test_fetch_luke_aliased(ds):
172151
name
173152
}
174153
'''.strip()
175-
query_dsl = ds.Query.human.args(id=1000).alias('luke').get(
154+
query_dsl = ds.Query.human.args(id=1000).alias('luke').select(
176155
ds.Character.name,
177156
)
178157
assert query == str(query_dsl)

0 commit comments

Comments
 (0)