graphql-inspector
graphql-inspector copied to clipboard
Validate complexity of documents
- Default complexity value should be
1
- Allow to define complexity by a directive
- Allow to match complexity value based on an argument (tricky and impossibru)
Very excited about this! I've thought about this concept quite a bit, and it's exciting to see it gain some traction in the community :)
I think that this should begin with defining some sort of specification for how to complexity of an operation is computed from the complexity of fields and how this works with arrays.
For instance, I could imagine a schema along the lines of
type user {
id: ID!
name: String!
favoriteColor: String @complexity(static: 3)
friends: [User!]! @complexity(per-item: 1)
wherein a query such as
query FriendsFavoriteColors {
user(id: "foo") {
id
friends {
name
favoriteColor
}
}
would be scored perhaps dynamically based on the size of the list, and where friends with a null
favorite color might not have the same complexity cost of 3. At the end of the day, this feature should be built in mind with trying to support some kind of complexity limiting, and I think needs to start with a definition of how operations interact with schema-defined complexity to receive scores.