quiz
quiz copied to clipboard
Is it possible to use fragments yet?
InlineFragment exists, but I can't figure out how to use it. I'm assuming that it's supposed to do what I want, and I just figured out how to make it look like what I want:
stuff = quiz.InlineFragment(schema.PullRequest, quiz.SelectionSet().number)
print(stuff.__gql__())
But when I put it in:
query = schema.query[
_
.repository(owner=owner, name=reponame)[
_
.project(number=5)[
_
.columns(first=1)[
_
.nodes[
_
.cards[
_
.edges[
_
.node[
_
.content[
stuff
]
]
]
]
]
]
]
]
]
it doesn't work because assert isinstance(selections, SelectionSet)
fails.
I haven't found any examples of how it's supposed to work, though.
Hi @waynew. Inline fragments are indeed not usable in the current release. They will be in the next release, which I'm working on now.
Your example would look like this:
import quiz
from quiz import SELECTOR as _
schema = ...
stuff = schema.PullRequest[
_.name
]
stuff
can then be used in a query as per your example
This is from the inline fragment test case in the new release:
class TestInlineFragment:
def test_gql(self):
# fmt: off
fragment = Dog[
_
.name
.bark_volume
.knows_command(command=Command.SIT)
.is_housetrained
.owner[
_.name
]
]
# fmt: on
assert (
gql(fragment)
== dedent(
"""\
... on Dog {
name
bark_volume
knows_command(command: SIT)
is_housetrained
owner {
name
}
}
"""
).strip()
)
@waynew FYI I'll probably remove python 3.5 support next release as well, since dataclasses
simplify a lot and are only available on 3.6+ (including backport)
As a workaround I was able to do this:
query = schema.query[
_
.repository(owner=owner, name=reponame)[
_
.project(number=5)[
_
.columns(first=1)[
_
.nodes[
_
.cards[
_
.edges[
_
.node[
_
.content
]
]
]
]
]
]
]
]
query = str(query).replace('content', f'content\n{{{stuff.__gql__()}}}')
Unfortunately I had to access the result as a dictionary, but at least I could still use the quiz API for building the query.