Closed m27315 closed 4 years ago
You need to use fragments as well, see https://sgqlc.readthedocs.io/en/latest/sgqlc.operation.html#inline-fragments-interfaces
as_tree = obj.__as__(Tree)
as_tree.name()
as_tree.type()
as_tree.oid()
something like this should work. The resulting graphql (once printed) should match the yours and when reading it back it will automatically check __typename
to detect if it's a Tree
, in such case it will instantiate that object instead of the generic interface or union.
Let me know if that works, if so paste the solution for further reference :-)
Thanks for the quick response and help, @barbieri! Based on your suggestion, here's the solution I used:
op = Operation(schema.Query)
orgid = op.organization(login="MyOrganization")
rid = orgid.repository(name="MyRepoName")
brid = rid.object(expression="master:")
as_tree = brid.__as__(schema.Tree)
entries = as_tree.entries()
entries.name()
entries.type()
entries.oid()
It appears that no cursor
or pageInfo
is supported on these, so I deleted references to that.
Ultimately, I'd like to make this recursive, so I could get all of the file names for a given repo, but this is a good start.
Thanks again, @barbieri!
There is no real recursion in GraphQL, so you need to expand "up to a level", then you can simply use a function that takes a selector as parameter and selects the fields and then call itself, reducing a counter so it knows when to stop.
Sorry, I couldn't think of a better title, because it represents my exact use case. ... How could I realize the following GraphQL query?
The hard part is the
Tree.entries
:Currently, I have something like this: