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

Reduce introspection complexity programmatically #4321

Open
ThePlenkov opened this issue Jan 10, 2025 · 3 comments · May be fixed by #4317
Open

Reduce introspection complexity programmatically #4321

ThePlenkov opened this issue Jan 10, 2025 · 3 comments · May be fixed by #4317

Comments

@ThePlenkov
Copy link

Use case

I'm trying to introspect Gitlab API schema with default introspection query .

Unfortunately Giltab API fails with the error: Query has complexity of 220, which exceeds max complexity of 217

I noticed that in a default query we use a static construction like which takes up to 10 nested levels:

fragment TypeRef on __Type {
      kind
      name
      ofType {
        kind
        name
        ofType {
          kind
          name
          ofType {
            kind
            name
            ofType {
              kind
              name
              ofType {
                kind
                name
                ofType {
                  kind
                  name
                  ofType {
                    kind
                    name
                    ofType {
                      kind
                      name
                      ofType {
                        kind
                        name
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

However in case of Gitlab API I'm ok to intentionally reduce complexity.

So if I use postman and just remove one nested level out then introspection works and I can test it in postman.

Of course - I can store this schema in a local file and then work it just by loading. But problem is - there are tons of different tools ( especially from The Guild ) which relies on this module and introspect using this default query.

I don't see here conflicts with a spec if we some explicitly tell what is our limit for the max depth.

Possible solution

If we introduce one more option depthLimit in IntrospectionOptions, Then we can just build mentioned above segment programmtically in a loop.

It may default to 10 as it is working now.

What do you think about this idea?

Thank you!

@benjie
Copy link
Member

benjie commented Jan 10, 2025

Typically the most nested these types would be is non-nullable list-of non-nullable list-of non-nullable thing; i.e. 5 "ofTypes". The default query allows for deeper than this, but honestly it's very rare to see a doubly-nested list, let alone triply nested.

You'll be happy to see this request has already been implemented in #4317; so consider adding a 👍 reaction to the issue description there.

@benjie benjie linked a pull request Jan 10, 2025 that will close this issue
@ThePlenkov
Copy link
Author

@benjie indeed - I also started my own implementation ( which is kind of same with recursion )

Should I park it or is ok to submit one more version for review?

@ThePlenkov
Copy link
Author

well , nevermind I checked the code - it's just doing exactly same. Let's stay with same PR indeed

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

Successfully merging a pull request may close this issue.

2 participants