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

Bug: Using a variable in multiple queries only works for first query #262

Open
hamidfzm opened this issue Jan 9, 2020 · 1 comment
Open
Assignees

Comments

@hamidfzm
Copy link

hamidfzm commented Jan 9, 2020

I'm using python graphql 2.2.1 with python 3.7. And here is my query:

query allPhotos($page: Int, $perPage: Int, $sortField: String, $sortOrder: String, $filter: PhotoFilter) {
  items: allPhotos(page: $page, perPage: $perPage, sortField: $sortField, sortOrder: $sortOrder, filter: $filter) {
    id
    photographer_id
    event_id
    source
    thumbnail
    created_at
    updated_at
    __typename
  }
  total: _allPhotosMeta(page: $page, perPage: $perPage, filter: $filter) {
    count
    __typename
  }

}

with the following variable:

{
  "filter": {"userId": "1"}
}

So here is what happens:
filter variable is only populated in allPhotos query and _allPhotosMeta filter variable is None. But if I add a new variable like filter2 equal to filter I get the correct result. This only happens in Python. It's ok in NodeJS.

@Cito Cito self-assigned this Jan 23, 2020
@Cito
Copy link
Member

Cito commented Jan 23, 2020

Can you post a complete test case?

Here is what I did trying to reprpduce it, but it works for me:

from graphql import *
from collections import OrderedDict


filter_type = GraphQLInputObjectType(
    "Filter",
    lambda: OrderedDict(
        [
            ("a", GraphQLInputObjectField(GraphQLString)),
            ("b", GraphQLInputObjectField(GraphQLString))
        ]
    )
)

def resolve_items(root, info, page, filter):
    print("Params for items:", page, filter)
    return ['first', 'second']

def resolve_total(root, info, page, filter):
    print("Params for total:", page, filter)
    return 2


query_type = GraphQLObjectType(
    "Query",
    {
        "all": GraphQLField(
            GraphQLList(GraphQLString),
            {
                "page": GraphQLArgument(GraphQLInt),
                "filter": GraphQLArgument(filter_type)
            },
            resolve_items),
        "total": GraphQLField(
            GraphQLInt,
            {
                "page": GraphQLArgument(GraphQLInt),
                "filter": GraphQLArgument(filter_type)
            },
            resolve_total)
    },
)


schema = GraphQLSchema(query_type)

query = '''
query Test($page: Int, $filter: Filter) {
    items: all(page: $page, filter: $filter),
    count: total(page: $page, filter: $filter)
}
'''

variables = {"page": 1, "filter": {"a": 1, "b": 2}}
result = graphql(schema, query, variable_values=variables)
print(result.data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants