quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

NullPointerException on GraphqQL server when request has syntax errors

Open alexfedorenchik opened this issue 2 years ago • 1 comments

Describe the bug

GraphQL server swallows syntax errors in request and throws NullPointeException.

Expected behavior

Invalid syntax error is returned to client. E.g. Invalid Syntax : offending token '[' at line 1 column 1

Actual behavior

Original Invalid syntax error is swallowed. Request failed later with NPE that is returned to client.

ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (vert.x-eventloop-thread-0) HTTP Request to /graphql failed, error id: 2883077a-96a7-42a9-9ff3-148a04feb8a0-1: java.lang.NullPointerException: Cannot invoke "graphql.language.Document.getDefinitionsOfType(java.lang.Class)" because "document" is null
	at io.smallrye.graphql.execution.context.SmallRyeContextManager.getRequestedOperationTypes(SmallRyeContextManager.java:253)
	at io.smallrye.graphql.execution.context.SmallRyeContextManager.populateFromExecutionInput(SmallRyeContextManager.java:102)
	at io.smallrye.graphql.execution.ExecutionService.execute(ExecutionService.java:155)
	at io.smallrye.graphql.execution.ExecutionService.executeAsync(ExecutionService.java:105)
	at io.quarkus.smallrye.graphql.runtime.SmallRyeGraphQLExecutionHandler.doRequest(SmallRyeGraphQLExecutionHandler.java:296)
	at io.quarkus.smallrye.graphql.runtime.SmallRyeGraphQLExecutionHandler.handlePost(SmallRyeGraphQLExecutionHandler.java:116)
	at io.quarkus.smallrye.graphql.runtime.SmallRyeGraphQLExecutionHandler.doHandle(SmallRyeGraphQLExecutionHandler.java:77)
	at io.quarkus.smallrye.graphql.runtime.SmallRyeGraphQLAbstractHandler.handleWithIdentity(SmallRyeGraphQLAbstractHandler.java:95)
	at io.quarkus.smallrye.graphql.runtime.SmallRyeGraphQLAbstractHandler.handle(SmallRyeGraphQLAbstractHandler.java:76)
	at io.quarkus.smallrye.graphql.runtime.SmallRyeGraphQLAbstractHandler.handle(SmallRyeGraphQLAbstractHandler.java:30)

How to Reproduce?

Send any request with syntax error (e.g. "[]") to graphql service using any client (e.g. graphql-ui).

Output of uname -a or ver

Darwin TEAL 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 x86_64

Output of java -version

openjdk 17.0.4 2022-07-19

GraalVM version (if different from Java)

OpenJDK Runtime Environment GraalVM CE 22.2.0 (build 17.0.4+8-jvmci-22.2-b06)

Quarkus version or git rev

2.12.0.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Gradle 7.5.1

Additional information

Screenshot 2022-09-17 at 19 39 50

alexfedorenchik avatar Sep 17 '22 16:09 alexfedorenchik

/cc @jmartisk, @phillip-kruger

quarkus-bot[bot] avatar Sep 19 '22 06:09 quarkus-bot[bot]

@jmartisk @phillip-kruger I really think we need to address this as it's an annoying issue for anyone using the GraphQL UI.

I can certainly provide a dump fix myself in smallry-graphql, but I am certain it won't be the proper solution as I don't have any of the necessary context

geoand avatar Nov 02 '22 07:11 geoand

Sure, we will look at this a.s.a.p. We can move this to SmallRye and close here ?

phillip-kruger avatar Nov 02 '22 07:11 phillip-kruger

Sounds good to me

geoand avatar Nov 02 '22 07:11 geoand

@phillip-kruger Any update on this? Seems like I'm still facing this issue ...

chberger avatar Mar 15 '23 16:03 chberger

This was fixed in SmallRye GraphQL 2.1.0, so that will be in Quarkus 3.0. With a build of the current Quarkus main branch, the response with the error is this:

{
  "errors": [
    {
      "message": "Unparseable input document",
      "locations": [],
      "extensions": {
        "classification": "DataFetchingException"
      }
    }
  ],
  "data": null
}

jmartisk avatar Mar 15 '23 17:03 jmartisk

@jmartisk thanks! I've just tested it with current release (2.16.X). Anyhow, seems like a backport isn't planned?

chberger avatar Mar 16 '23 12:03 chberger

@chberger, ok I'll prepare a backport to 2.16, it might get into 2.16.5 or 2.16.6, not sure about the current exact schedule

jmartisk avatar Mar 16 '23 13:03 jmartisk

@jmartisk I can wait for you if you plan to push the fix soon.

gsmet avatar Mar 16 '23 13:03 gsmet

Ok I've kicked off a release of SmallRye GraphQL 1.9.4. If it passes, I can send an upgrade PR to Quarkus later today. Or anybody else can, simply bumping the version should be enough.

jmartisk avatar Mar 16 '23 13:03 jmartisk

@jmartisk I created the PR and asked for your approval there.

gsmet avatar Mar 16 '23 14:03 gsmet

@chberger, ok I'll prepare a backport to 2.16, it might get into 2.16.5 or 2.16.6, not sure about the current exact schedule

Cool :-) Thank you!

chberger avatar Mar 16 '23 16:03 chberger

As the fix is now in 2.16.5 and in the main branch, I think we can close this now.

jmartisk avatar Mar 22 '23 06:03 jmartisk