`connectionParams` for Subscriptions are not resolved
roeb opened this issue · 11 comments
Issue workflow progress
Progress of the issue based on the
Contributor Workflow
- 1. The issue provides a reproduction available on
Github,
CodeSandbox
Make sure to fork this template and run
yarn generate
in the terminal.Please make sure Mesh package versions under
package.json
matches yours.
- 2. A failing test has been provided
- 3. A local solution has been provided
- 4. A pull request is pending review
Describe the bug
We want to use the GraphQL mesh to forward a subscription request to an Apollo GraphQL server behind it. The forwarding works and the subscription arrives successfully in Apollo.
However, we are missing the passed connection parameters. Here the interpolation does not seem to work. We could check with an additional resolver that the connection parameters sent by the client arrive successfully in the GraphQL mesh, but are not passed on to the Apollo.
The following arrives at the Apollo:
{
"Authorization": "{context.connectionParams['authorization']}",
"Tenant": "{context.connectionParams['tenant']}"
}
The headers for queries and mutations arrive successfully and correctly resolved at Apollo. The problem exists only for the connection parameters of subscriptions.
To Reproduce Steps to reproduce the behavior:
.meshrc.yml
sources:
- name: internal
handler:
graphql:
endpoint: '${INTERNAL_GRAPHQL_ENDPOINT}'
source: ../../Apollo/src/schema.graphql
operationHeaders:
Authorization: "{context.headers['authorization']}"
Tenant: "{context.headers['tenant']}"
connectionParams:
Authorization: "{context.connectionParams['authorization']}"
Tenant: "{context.connectionParams['tenant']}"
...
Expected behavior
The GraphQL mesh should correctly resolve the connection parameters passed by the client and forward them to the Apollo server.
The following SHOULD be arrived in Apollo:
{
"Authorization": "MY_TOKEN",
"Tenant": "MY_TENANT"
}
Environment:
- OS: MacOS 13.3.1
@graphql-mesh/cli
: "^0.86.1",@graphql-mesh/graphql
: "^0.95.1",@graphql-mesh/plugin-operation-field-permissions
: "^0.95.1",@graphql-mesh/runtime
: "^0.96.1",@graphql-mesh/transform-filter-schema
: "^0.95.1",- NodeJS: 18.16.1
Additional context
Could you provide a reproduction on CodeSandbox or StackBlitz? Thanks!
Hi @ardatan, I have added a link to a GitHub repo and a CodeSandbox link in my post above. Unfortunately there is a problem with Yoga GraphiQL. But in every other GraphQL client it works. I hope this helps?
Hmm YogaGraphiQL uses SSE not WS so there is no connectionParams in the context while connecting via SSE since it is still HTTP
When I mount an AdditionalResolver in GraphQL Mesh that processes subscriptions, I have the connectionParams
there. Also, I don't use YogaGraphiQL at all but Banana Cake Pop or Apollo Studio as a client. They all go through WS.
I see. Currently Mesh's GraphiQL uses SSE only. This should be configurable in Mesh's configration file and GraphiQL needs to have a tab for connection params.
I'm sorry, but I think we misunderstand each other.
I don't use YogaGraphiQL and I don't want to. I have the problem with any client lib or app. Even from a React application. There I go via websockets (graphl-ws
) to our GraphQL mesh http://localhost:4000
and it should pass the subscription to the Apollo http://localhost:3500
. It does this without any problems and the subscriptions work.
Only the connection params passed by the client arrive at the GraphQL Mesh, but are not passed on to the Apollo.
The values from the connection params (Authorization: "TOKEN"
) that arrive in the GraphQL mesh are not resolved, but only the path of the connection params arrives as a string in Apollo "(Authorization": "{context.connectionParams['authorization']}"
).
Ok I understand. The GraphQL source doesn't receive the connection parameters. Is it possible for you to create a small reproduction on CodeSandbox or StackBlitz?
I have added a React app to my example from above, which provides the correct connection parameters. Unfortunately they are not resolved correctly in GraphQL Mesh (see console log output from Apollo after the client connects).
Unfortunately, I don't get Apollo, GraphQL Mesh and a Vite React app to launch in the CodeSandbox. But Apollo and GraphQL Mesh launch. If you copy the URL with port 4000 and give it locally in a client, you will see the problem too (instructions in the README).
Of course you can also clone the repo and start everything locally including the React app.
CodeSandbox: https://codesandbox.io/p/sandbox/github/roeb/graphql-mesh-apollo-sample/tree/main
GitHub Repo: https://github.com/roeb/graphql-mesh-apollo-sample
@roeb I have exactly the same problem! Did you found a solution?
@roeb After hours of debugging and trying to understand how everything works together I hopefully found the solution.
It's in my case a problem with the graphql-ws
-executor in the https://github.com/ardatan/graphql-tools repository. .
The configuration of the graphql-ws
initialization get's overwritten. After the fix in the PR below the connectionParams
getting resolved.