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

Add Support to Limit the Maximum Depth of a Query #938

Closed
Assignees
Labels
module/graphql Issues related to Ballerina GraphQL module Type/Improvement Type/Task

Comments

@ThisaruGuruge
Copy link
Member

ThisaruGuruge commented Feb 5, 2021

GraphQL service should be able to provide a way to limit the depth of an accepted query, so that too deep queries will not be executed, but invalidated at the validation phase.

Consider the following example, where there is a cyclic reference between the Book and the Author records.

import ballerina/graphql;

graphql:ListenerConfiguration configs = { maxQueryDepth: 3 }
listener graphql:Listener graphqlListener = new(9090, configs);

service /graphql on graphqlListener {
    isolated resource function get book(int id) returns Book {
        // Get Book record from somewhere and return
    }
}

type Book record {|
    string title;
    Author author;
|};

type Author record {|
    string name;
    Book[] books;
|};

Someone can exploit this cyclic reference to send a too deep query in order to break the service as below:

{
    book(id: 1) {
        author {
            books {
                author {
                    books {
                        author {
                            books {
                                author {
                                    // This can go on like this forever
                                    name
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Therefore developers should be able to limit the maximum depth for a query to be valid, before execute it.

Subtask of #710

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/graphql Issues related to Ballerina GraphQL module Type/Improvement Type/Task
Projects
None yet
1 participant