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

connectionParams for Subscriptions are not resolved #5774

Closed
1 of 4 tasks
roeb opened this issue Aug 2, 2023 · 11 comments · Fixed by ardatan/graphql-tools#5666
Closed
1 of 4 tasks

connectionParams for Subscriptions are not resolved #5774

roeb opened this issue Aug 2, 2023 · 11 comments · Fixed by ardatan/graphql-tools#5666

Comments

@roeb
Copy link

roeb commented Aug 2, 2023

Issue workflow progress

Progress of the issue based on the
Contributor Workflow

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

@ardatan
Copy link
Owner

ardatan commented Aug 2, 2023

Could you provide a reproduction on CodeSandbox or StackBlitz? Thanks!

@roeb
Copy link
Author

roeb commented Aug 3, 2023

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?

@ardatan
Copy link
Owner

ardatan commented Aug 3, 2023

Hmm YogaGraphiQL uses SSE not WS so there is no connectionParams in the context while connecting via SSE since it is still HTTP

@roeb
Copy link
Author

roeb commented Aug 3, 2023

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.

@ardatan
Copy link
Owner

ardatan commented Aug 3, 2023

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.

@roeb
Copy link
Author

roeb commented Aug 3, 2023

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']}").

@ardatan
Copy link
Owner

ardatan commented Aug 3, 2023

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?

@roeb
Copy link
Author

roeb commented Aug 3, 2023

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
Copy link
Author

roeb commented Aug 9, 2023

@ardatan any news?

@ThomasMoritz
Copy link

@roeb I have exactly the same problem! Did you found a solution?

@ThomasMoritz
Copy link

@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 connectionParamsgetting resolved.

PR: ardatan/graphql-tools#5666

This was referenced Apr 30, 2024
This was referenced May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants