Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using variables in a query on a sub graph causes an error #7937

Open
maartenkools opened this issue Jan 21, 2025 · 2 comments
Open

Using variables in a query on a sub graph causes an error #7937

maartenkools opened this issue Jan 21, 2025 · 2 comments

Comments

@maartenkools
Copy link

Product

Hot Chocolate

Version

14.3.0

Link to minimal reproduction

https://github.com/maartenkools/hc-fusion-duplicate-vars/tree/main

Steps to reproduce

Start the Server and Gateway projects from the sample repo, and execute the following query:

query getItems($groupId: String! = "groupId") {
  items(groupId: $groupId) {
    values(groupId: $groupId)
  }
}

The server has the following schema:

type Query {
    items(groupId: String): [Item!]!
}

type Item {
    values(groupId: String!): [String!]!
}

Key point is that groupId is optional for the items query, while it's mandatory for values.

What is expected?

The query executes successfully (in case of the repo, an empty array is returned)

What is actually happening?

An error occurs:

Using HC 13.9.7:

{
  "errors": [
    {
      "message": "An item with the same key has already been added. Key: groupId",
      "extensions": {
        "code": "HC0012"
      }
    }
  ]
}

Using HC 14.3.0 and up:

{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "items"
      ],
      "extensions": {
        "code": "HC0018"
      }
    },
    {
      "message": "An item with the same key has already been added. Key: groupId",
      "extensions": {
        "code": "HC0012"
      }
    }
  ]
}

In both cases the following query plan is generated:

{
    "queryPlan": {
        "document": "query getItems($groupId: String! = \"groupId\") { items(groupId: $groupId) { values(groupId: $groupId) } }",
        "operation": "getItems",
        "rootNode": {
            "type": "Sequence",
            "nodes": [{
                    "type": "Resolve",
                    "subgraph": "Subgraph",
                    "document": "query getItems_1($groupId: String! = \"groupId\", $groupId: String = \"groupId\") { items(groupId: $groupId) { values(groupId: $groupId) } }",
                    "selectionSetId": 0,
                    "forwardedVariables": [{
                            "variable": "groupId"
                        }, {
                            "variable": "groupId"
                        }
                    ]
                }, {
                    "type": "Compose",
                    "selectionSetIds": [
                        0
                    ]
                }
            ]
        }
    }
}

Relevant log output

Additional context

Possibly related to #7365?

@michaelstaib
Copy link
Member

This issue is fixed with the new variable batching in fusion 15.

@michaelstaib
Copy link
Member

Hot Chocolate 14 already implements this new protocol but the current fusion implementation is not yet taking advantage of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants