Skip to content

Query has depth of 13, which exceeds max depth of 10 #290

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

Closed
honzajavorek opened this issue Jan 25, 2022 · 5 comments
Closed

Query has depth of 13, which exceeds max depth of 10 #290

honzajavorek opened this issue Jan 25, 2022 · 5 comments
Labels
type: question or discussion Issue discussing or asking a question about gql

Comments

@honzajavorek
Copy link

honzajavorek commented Jan 25, 2022

I'm using gql to fetch data from the Memberful API. After upgrading to v3, I get the following error:

[gql.transport.requests] INFO: >>> {"query": "query IntrospectionQuery {\n  __schema {\n    queryType {\n      name\n    }\n    mutationType {\n      name\n    }\n    subscriptionType {\n      name\n    }\n    types {\n      ...FullType\n    }\n    directives {\n      name\n      description\n      locations\n      args {\n        ...InputValue\n      }\n    }\n  }\n}\n\nfragment FullType on __Type {\n  kind\n  name\n  description\n  fields(includeDeprecated: true) {\n    name\n    description\n    args {\n      ...InputValue\n    }\n    type {\n      ...TypeRef\n    }\n    isDeprecated\n    deprecationReason\n  }\n  inputFields {\n    ...InputValue\n  }\n  interfaces {\n    ...TypeRef\n  }\n  enumValues(includeDeprecated: true) {\n    name\n    description\n    isDeprecated\n    deprecationReason\n  }\n  possibleTypes {\n    ...TypeRef\n  }\n}\n\nfragment InputValue on __InputValue {\n  name\n  description\n  type {\n    ...TypeRef\n  }\n  defaultValue\n}\n\nfragment TypeRef on __Type {\n  kind\n  name\n  ofType {\n    kind\n    name\n    ofType {\n      kind\n      name\n      ofType {\n        kind\n        name\n        ofType {\n          kind\n          name\n          ofType {\n            kind\n            name\n            ofType {\n              kind\n              name\n              ofType {\n                kind\n                name\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}"}
[gql.transport.requests] INFO: <<< {"errors":[{"message":"Query has depth of 13, which exceeds max depth of 10"}]}

I'm not really a GraphQL expert, but this is not a query I can see anywhere in my code. It looks like gql does this IntrospectionQuery on my behalf. I've learned the depth limitation is a common practice and it's something the backend (server) imposes on me, so it isn't anything I can influence myself.

Thus as I understand the situation, gql constructs a query the server refuses to execute and I can do nothing about it. That seems to me as a bug in the library, because v2 has worked with the same API and the same code.

To Reproduce
I'm sending the following query to the Memberful API:

        query getSubscriptions($cursor: String!) {
            subscriptions(after: $cursor) {
                totalCount
                pageInfo {
                    endCursor
                    hasNextPage
                }
                edges {
                    node {
                        active
                        createdAt
                        expiresAt
                        pastDue
                        coupon {
                            code
                        }
                        orders {
                            createdAt
                            coupon {
                                code
                            }
                        }
                        member {
                            discordUserId
                            email
                            fullName
                            id
                            stripeCustomerId
                        }
                    }
                }
            }
        }

Expected behavior
I get a result with data.

System info (please complete the following information):

  • OS: macOS, but probably not relevant
  • Python version: 3.8
  • gql version: 3
  • graphql-core version: poetry.lock says it's 3.2.0
@leszekhanusz
Copy link
Collaborator

leszekhanusz commented Jan 25, 2022

gql will use an introspection query to get the schema from the backend only if fetch_schema_from_transport is set to True in the Client init. See schema validation documentation

You should try with fetch_schema_from_transport=False (which is the default behavior if fetch_schema_from_transport is not set).

@leszekhanusz leszekhanusz added the type: question or discussion Issue discussing or asking a question about gql label Jan 25, 2022
@honzajavorek
Copy link
Author

honzajavorek commented Jan 26, 2022

Thanks, this seems* to help! Honestly, it's a while since I wrote the code and now I don't know why I had this set to True explicitly. However, isn't it strange that it works with v2?

* it throws a different error now, which I think isn't related to this issue, probably just to the upgrade to v3. I will come back to report if this really solves the problem.

@leszekhanusz
Copy link
Collaborator

I don't know why I had this set to True explicitly.

Probably because it is set to True in some of our examples.

However, isn't it strange that it works with v2?

We changed the way the introspection query is done in 3.0 (See the release notes for breaking changes)
I think that in 2.x, if you received an error with the introspection query, then this error was silently discarded. This is no more the case in 3.0

@honzajavorek
Copy link
Author

Thanks, that makes sense :) I just got it all working. The subsequent error was

...
  File "/Users/honza/Projects/juniorguru/juniorguru/sync/subscriptions.py", line 88, in main
    result = memberful.execute(query, params)
  File "/Users/honza/Library/Caches/pypoetry/virtualenvs/juniorguru-Lgaxwd2n-py3.8/lib/python3.8/site-packages/gql/client.py", line 193, in execute
    return self.execute_sync(document, *args, **kwargs)
  File "/Users/honza/Library/Caches/pypoetry/virtualenvs/juniorguru-Lgaxwd2n-py3.8/lib/python3.8/site-packages/gql/client.py", line 137, in execute_sync
    return session.execute(document, *args, **kwargs)
  File "/Users/honza/Library/Caches/pypoetry/virtualenvs/juniorguru-Lgaxwd2n-py3.8/lib/python3.8/site-packages/gql/client.py", line 435, in execute
    result = self._execute(
  File "/Users/honza/Library/Caches/pypoetry/virtualenvs/juniorguru-Lgaxwd2n-py3.8/lib/python3.8/site-packages/gql/client.py", line 356, in _execute
    result = self.transport.execute(
TypeError: execute() got multiple values for argument 'variable_values'

This happened with code

from gql import Client as Memberful, gql
from gql.transport.requests import RequestsHTTPTransport
...
transport = RequestsHTTPTransport(url='https://juniorguru.memberful.com/api/graphql/',
                                  headers={'Authorization': f'Bearer {MEMBERFUL_API_KEY}'},
                                  verify=True, retries=3)
memberful = Memberful(transport=transport)
...
result = memberful.execute(query, params)

After digging into code of .execute() and then code of the requests transport I tried to change the last line to:

- result = memberful.execute(query, params)
+ result = memberful.execute(query, variable_values=params)

This has made the error to go away. I didn't see this mentioned in the release notes, so I'm not sure whether this is intended behavior or not. That's also why I'm adding a comment here and not filing another issue. If you think this is intended, I'm fine with the change, but just wanted to let you know in case it's unexpected.

@leszekhanusz
Copy link
Collaborator

I've updated the release notes for your last point. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about gql
Projects
None yet
Development

No branches or pull requests

2 participants