Skip to content

Commit 9b988c5

Browse files
committed
Add a test for PyEnum query arguments
1 parent 98733fb commit 9b988c5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

graphene_sqlalchemy/tests/test_query.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,42 @@ def resolve_pet(self, info, kind=None, *args, **kwargs):
151151
assert result.data == expected, result.data
152152

153153

154+
def test_py_enum_parameter(session):
155+
setup_fixtures(session)
156+
157+
class PetType(SQLAlchemyObjectType):
158+
class Meta:
159+
model = Pet
160+
161+
class Query(graphene.ObjectType):
162+
pet = graphene.Field(PetType, kind=graphene.Argument(PetType._meta.fields['hair_kind'].type.of_type))
163+
164+
def resolve_pet(self, info, kind=None, *args, **kwargs):
165+
query = session.query(Pet)
166+
if kind:
167+
# XXX Why kind passed in as a str instead of a Hairkind instance?
168+
query = query.filter(Pet.hair_kind == Hairkind(kind))
169+
return query.first()
170+
171+
query = """
172+
query PetQuery($kind: Hairkind) {
173+
pet(kind: $kind) {
174+
name,
175+
petKind
176+
hairKind
177+
}
178+
}
179+
"""
180+
expected = {"pet": {"name": "Lassie", "petKind": "dog", "hairKind": "LONG"}}
181+
schema = graphene.Schema(query=Query)
182+
result = schema.execute(query, variables={"kind": "SHORT"})
183+
assert not result.errors
184+
assert result.data == {"pet": None}
185+
result = schema.execute(query, variables={"kind": "LONG"})
186+
assert not result.errors
187+
assert result.data == expected, result.data
188+
189+
154190
def test_should_node(session):
155191
setup_fixtures(session)
156192

0 commit comments

Comments
 (0)