Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use fragments yet? #286

Open
waynew opened this issue Jan 10, 2020 · 3 comments
Open

Is it possible to use fragments yet? #286

waynew opened this issue Jan 10, 2020 · 3 comments
Assignees
Labels
in develop The issue has been addressed in the develop branch

Comments

@waynew
Copy link

waynew commented Jan 10, 2020

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.

@ariebovenberg
Copy link
Owner

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()
        )

@ariebovenberg ariebovenberg added the in develop The issue has been addressed in the develop branch label Jan 11, 2020
@ariebovenberg ariebovenberg self-assigned this Jan 11, 2020
@ariebovenberg
Copy link
Owner

@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)

@waynew
Copy link
Author

waynew commented Jan 14, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in develop The issue has been addressed in the develop branch
Projects
None yet
Development

No branches or pull requests

2 participants