quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.36k stars 2.56k forks source link

Wrong GraphQL context injected when using @Source in non-blocking mode with multiple operations #28928

Open ddelbondio opened 1 year ago

ddelbondio commented 1 year ago

Describe the bug

Given following setup:

public Child child(@Source Parent1 parent1, Context context) {
    Child obj = new Child();
    obj.selectedFields = context.getSelectedFields().toString();
    obj.path = context.getPath();
    return obj;
}

When calling an API with multiple operations in one call, while using non-blocking GraphQL mode Quarkus, the injected context refers to the last operation instead of the context of the "child" field in Parent1.

Using quarkus.smallrye-graphql.nonblocking.enabled=false fixes the behaviour.

Expected behavior

The correct context should be injected and the call result should look like:

{
  "data": {
    "parent1": {
      "child": {
        "path": "/parent1/child",
        "selectedFields": "[\"path\",\"selectedFields\"]"
      }
    },
    "parent2": {
      "parent2Value": "value2"
    }
  }
}

Actual behavior

The actual result looks like:

{
  "data": {
    "parent1": {
      "child": {
        "path": "/parent2/parent2Value",
        "selectedFields": "[]"
      }
    },
    "parent2": {
      "parent2Value": "value2"
    }
  }
}

How to Reproduce?

Reproducer: https://github.com/ddelbondio/quarkus-graphql-context-bug

Steps to reproduce:

  1. Run following query:
query {
  parent1 {
    child {
      path
      selectedFields
    }
  }
  parent2 {
    parent2Value
  }
}
  1. Observe returned result

Output of uname -a or ver

Microsoft Windows [Version 10.0.19045.2130]

Output of java -version

openjdk version "11.0.12" 2021-07-20 OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7) OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.13.3.Final

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

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)

Additional information

No response

quarkus-bot[bot] commented 1 year ago

/cc @jmartisk, @phillip-kruger