
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@kiwicom/graphql-result-size
Advanced tools
This module provides an implementation of an algorithm that calculates the (exact) size of GraphQL response objects without actually producing the response.
This module provides an implementation of an algorithm that calculates the (exact) size of GraphQL response objects without actually producing the response. Hence, this module can be used to check whether the size of the response to a GraphQL query exceeds a given threshold. In this sense, the module should be used as a dependency in GraphQL server frameworks that execute the server-side runtime process of GraphQL.
Based on Algorithm 2 of the research paper Semantics and Complexity of GraphQL by Olaf Hartig and Jorge Pérez. Since this research paper is pretty dense and math-heavy, you may first want to read a more lightweight, high-level summary of the paper.
Please note: our implementation differs from the referential implementation in a few cases:
This algorithm is not a good fit if you need to calculate the score of your query/fragment. It calculates scores of responses. Therefore it doesn't say much about the query/fragment size.
Look at the following query from the article.
query {
start {
advisor {
univ {
name
}
}
friend {
univ {
name
}
}
}
}
This query will yield the following minimal (syntactically correct) response:
start: {
advisor: {
univ: { name: xxx }
}
friend: {
univ: { name: xxx }
}
}
We measure the size of GraphQL query results in terms of symbols, where every field name counts as a symbol, and so does every scalar value and every special character (such as colons and curly braces). For instance, the aforementioned result of our example query happens to be of size 26. However, we want to calculate this size without already having produced the query result.
Why is the response size 26?
7 field names
2 scalars
7 colons
10 braces
---
26
In more math-y notation following the algorithm from the paper:
4 + x
4 + size(q1,u) + size(q2,u) 4 + 11 + 11 = 26
size(q1,u) = 4 + size(q3,v) 4 + 7
size(q3,v) = 4 + size(q4,w) 4 + 3
q4 = name we see that the result of subquery q4 is 'name:xxx' and, thus, contains exactly 3 symbols
Please note that we don't have to calculate size(q2,u) again since it's already calculated by size(q1,u) and the response types are identical (therefore we can reuse it and keep this algorithm linear).
Another example:
{
me {
friends(first: 1) {
name
}
}
}
↓ ↓ ↓
me: {
friends: [
{
name: xxx
}
]
}
↓ ↓ ↓
= 13
FAQs
This module provides an implementation of an algorithm that calculates the (exact) size of GraphQL response objects without actually producing the response.
The npm package @kiwicom/graphql-result-size receives a total of 1 weekly downloads. As such, @kiwicom/graphql-result-size popularity was classified as not popular.
We found that @kiwicom/graphql-result-size demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 17 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.