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

How do you pass a list as a kwarg? #285

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

How do you pass a list as a kwarg? #285

waynew opened this issue Jan 10, 2020 · 3 comments
Assignees
Labels
bug Something isn't working in develop The issue has been addressed in the develop branch

Comments

@waynew
Copy link

waynew commented Jan 10, 2020

I'm trying to translate a query like this GitHub query:

query {
  repository(owner: "ariebovenberg", name: "quiz") { 
    
    issues (last:3, states: [OPEN, CLOSED]) {
      pageInfo {
        endCursor
        startCursor
      }
      nodes{
        title
        number
        state
        closed
        closedAt
        createdAt
        labels(first:100) {
          edges {
            node {
              name
            }
          }
        }
      }
    }
  }
}

To quiz.

I expected this to work:

    query = schema.query[                                                                                 
        _                                                                       
        .repository(owner=owner, name=reponame)[                                
            _                                                                   
            .issues(first=3, states=[schema.IssueState.OPEN, schema.IssueState.CLOSED])[
                _                                                               
                .pageInfo [                                                     
                    _                                                           
                    .endCursor                                                  
                ]                                                               
                .nodes[                                                         
                    _                                                           
                    .title                                                      
                    .number                                                     
                    .state                                                      
                    .closed                                                     
                    .closedAt                                                   
                    .createdAt                                                  
                    .labels(first=100) [                                        
                        _                                                       
                        .edges [                                                
                            _                                                   
                            .node [                                             
                                _                                               
                                .name                                           
                            ]                                                   
                        ]                                                       
                    ]                                                           
                ]                                                               
            ]                                                                   
        ]                                                                       
    ]                

but it tells me that TypeError: Cannot serialize to GraphQL: <class 'list'>

So what am I doing wrong here? I couldn't find any examples in the docs or examples.

@waynew
Copy link
Author

waynew commented Jan 10, 2020

Well, I know this is the very wrong way to fix the problem, but I just added this to build.py:

argument_as_gql.register(list, lambda x: "[{}]".format(','.join(argument_as_gql(thing) for thing in x)))

And now it works for me. I wasn't able to find anything else in the docs or code that suggested I should be doing something a different way, and trying to pass a list of any type breaks on serialization, even though it does pass the validation step.

@waynew
Copy link
Author

waynew commented Jan 10, 2020

Aaand as a bit of a follow up - I was able to put this workaround in my own code:

import quiz
import quiz.build

quiz.build.argument_as_gql.register(list, lambda x: "[{}]".format(','.join(quiz.build.argument_as_gql(thing) for thing in x))) 

Ugly hack, but it works for me, and doesn't require patching the quiz files 👍

@ariebovenberg
Copy link
Owner

Hi @waynew, thanks for opening the issue. If this is something supported by the GraphQL spec, then quiz should support it. I'll have a look at fixing this.

@ariebovenberg ariebovenberg added bug Something isn't working in develop The issue has been addressed in the develop branch labels Jan 10, 2020
@ariebovenberg ariebovenberg self-assigned this Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in develop The issue has been addressed in the develop branch
Projects
None yet
Development

No branches or pull requests

2 participants