Skip to content

Operation name not parsed from query string if operationName JSON field omitted from POST request #264

Closed
@yonigibbs

Description

@yonigibbs

Description
When Actuator is used in a Spring Boot app using graphql-spring-boot-starter, metrics data is created whenever a GraphQL endpoint is hit. One of the tags is operationName. This should be the name of the GraphQL operation. If the GraphQL call is as follows, then this works correctly:

{
	"operationName": "MyOperationName"
	"query": "query MyOperationName { ... }"
}

However, it doesn't work if the operationName JSON field is omitted (but the operation name is still included in the text of the query JSON field), i.e. the JSON posted is as follows:

{
	"query": "query MyOperationName { ... }"
}

In this case, the operationName tag is set to "unknown".

The GraphQL spec seems to suggest that the operationName JSON field is only required if there is more than one query. If there is only query, it should be read from the text of the query JSON field: https://spec.graphql.org/June2018/#GetOperation(). So I think maybe that is missing from the code in this library?

I logged this in this repo as, although it manifested for me when using the Spring Boot dependency, I believe the issue might be in this library, as it is here that the HTTP request is read, in GraphQLObjectMapper, I think. If this is incorrect let me know and I'll log it in the graphql-spring-boot-starter repo. (The use of Actuator is itself irrelevant, but it's the way I discovered that the operation name didn't seem to be read correctly.)

To Reproduce
There's a repro here: https://github.com/yonigibbs/gqlopname. This contains a unit test that demonstrates the error. Happy to provide more info if required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions