Apollo Sandbox, Subscription and connectionParams?

Hello,

I’m using the subscription pattern described in the Apollo Doc for onConnect and validation of JWT using the connectionParams. It works well when using a client that can insert the connectionParams information. However, the Apollo Sandbox does not have a user interface to insert connectionParams.

I tried to include the JWT inside the headers portion of the UI and then within the server code (onConnect) function to access the headers, but without success. No header information is provided in the onConnect argument of type GraphQLSubscriptionContext.

In the end, using the Apollo Sandbox has no way to pass credentials. Not by header, not by the cookie, and not by connectionParams.

What is the way to get authentication information using Apollo Sandbox on a Subscription connection?

Thank you,

2 Likes

Hey @MrDesjardins, thanks for pointing this out. I brought it up to the team and we’re looking at adding something for connectionParams.

2 Likes

@watson Thanks for the fast response. I’ve been wondering how can back-end devs simulate connectionParams for Subscriptions without bothering front-end devs and just using Apollo Sandbox, so that when it’s given to the front-end devs, it’s ready and tested and found this thread.

const wsLink = new GraphQLWsLink(
  createClient({
    url: 'ws://localhost:4000/subscriptions',
    connectionParams: {
      authentication: user.authToken,
    },
  }),
);

Just in case somebody needs to make it work while Apollo team is working on connectionParams to be added in Apollo Sandbox, I’m currently using https://altairgraphql.dev/ to develop on subscriptions as they have connectionParams.

We’re missing this feature too, as we currently can’t use the sandbox behind Google’s IAP protection, as it requires passing through the credentials: Managing IAP sessions  |  Identity-Aware Proxy  |  Google Cloud