You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The query name and the query variables are padded, causing a inconsistent hashing with Apollo Router's feature called Safelisting
For example, for this query,
mutation CreatePost($userId: ID!, $postInput: PostInput!) {
createPost(userId: $userId, input: $postInput) {
...PostFields
author {
...UserFields
}
}
}
fragment UserFields on User { id name email age }
fragment PostFields on Post { id title content createdAt }
or equivalent
fragment UserFields on User { id name email age } fragment PostFields on Post { id title content createdAt } query GetUserWithPosts($userId: ID!) { user(id: $userId) { ...UserFields posts { ...PostFields comments { id text } } } } query GetAllUsers { users { ...UserFields totalPosts } } mutation CreateUserPost($userId: ID!, $postInput: PostInput!) { createPost(userId: $userId, input: $postInput) { ...PostFields author { ...UserFields } } }
Notice there's a space padded between CreateUserPost and ($userId: ID!, $postInput: PostInput!), and also ... and UserFields
Unfortunately, this doesn't match Apollo's normalization rule so the formatted string is slightly different.
What did you expect?
I expect to see no space between operation name and the arguments. I think the problem is in FormatOperationDefinition where it called WriteWord, the padding configure is set to true so padding was added.
Minimal graphql.schema and models to reproduce
An example is above, and this is the current set up to produce the the same normalized string with Apollo. Without this, our ID will be inconsistent.
var buf strings.Builder
// Create a formatter configured for Apollo's style
formatter := formatter.NewFormatter(buf,
formatter.WithIndent(" "), // Use two spaces for indentation
)
formatter.FormatQueryDocument(doc)
normalizedQuery := buf.String()
normalizedQuery = strings.ReplaceAll(normalizedQuery, " (", "(") // Remove space before parentheses
normalizedQuery = strings.ReplaceAll(normalizedQuery, "... ", "...") // Remove space before parentheses
normalizedQuery = strings.TrimSpace(normalizedQuery) // Remove trailing newlines and whitespace
versions
go list -m github.com/vektah/gqlparser/v2?
go version?
github.com/vektah/gqlparser/v2 v2.5.16
go version go1.23.3 darwin/arm64
The text was updated successfully, but these errors were encountered:
Hey, thanks for filing this issue. I would welcome a pull request for this, as I think the community would benefit from it.
Are you able to provide one?
What happened?
The query name and the query variables are padded, causing a inconsistent hashing with Apollo Router's feature called Safelisting
For example, for this query,
or equivalent
fragment UserFields on User { id name email age } fragment PostFields on Post { id title content createdAt } query GetUserWithPosts($userId: ID!) { user(id: $userId) { ...UserFields posts { ...PostFields comments { id text } } } } query GetAllUsers { users { ...UserFields totalPosts } } mutation CreateUserPost($userId: ID!, $postInput: PostInput!) { createPost(userId: $userId, input: $postInput) { ...PostFields author { ...UserFields } } }
calling FormatQueryDocument would result in
mutation CreateUserPost ($userId: ID!, $postInput: PostInput!) {\n createPost(userId: $userId, input: $postInput) {\n ... PostFields\n author {\n ... UserFields\n }\n }\n}\nquery GetAllUsers {\n users {\n ... UserFields\n totalPosts\n }\n}\nquery GetUserWithPosts ($userId: ID!) {\n user(id: $userId) {\n ... UserFields\n posts {\n ... PostFields\n comments {\n id\n text\n }\n }\n }\n}\nfragment PostFields on Post {\n id\n title\n content\n createdAt\n}\nfragment UserFields on User {\n id\n name\n email\n age\n}\n
Notice there's a space padded between
CreateUserPost
and($userId: ID!, $postInput: PostInput!)
, and also...
andUserFields
Unfortunately, this doesn't match Apollo's normalization rule so the formatted string is slightly different.
What did you expect?
I expect to see no space between operation name and the arguments. I think the problem is in FormatOperationDefinition where it called WriteWord, the padding configure is set to true so padding was added.
Minimal graphql.schema and models to reproduce
An example is above, and this is the current set up to produce the the same normalized string with Apollo. Without this, our ID will be inconsistent.
versions
go list -m github.com/vektah/gqlparser/v2
?go version
?The text was updated successfully, but these errors were encountered: