question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

doc: Subscription example doesn't include connection param

See original GitHub issue

Hi, query and mutation work perfectly but not working with subscription.

When i try to call ctx.getUser(), ctx.isAuthenticated() or ctx.isUnauthenticated() will get the following errors: Cannot read property ‘user’ of undefined Cannot read property ‘isAuthenticated’ of undefined Cannot read property ‘isUnauthenticated’ of undefined

Also, there is a type errors on createOnConnected() which is

Type ‘(connectionParams: Object, webSocket: WebSocket<Request<ParamsDictionary, any, any, Query>>) => Promise<ReturnOnConnect>’ is not assignable to type ‘(connectionParams: Object, websocket: WebSocket, context: ConnectionContext) => any’. Types of parameters ‘webSocket’ and ‘websocket’ are incompatible. Property ‘upgradeReq’ is missing in type ‘WebSocket’ but required in type ‘WebSocket<Request<ParamsDictionary, any, any, Query>>’.ts(2322) types.d.ts(33, 5): ‘upgradeReq’ is declared here.

here is the server

const server = new ApolloServer({
  schema,
  context: ({ req, res }) => buildContext({ req, res, prisma, pubsub }),
  playground: {
    settings: {
      "request.credentials": "include",
    },
  },
  subscriptions: {
    // @ts-ignore
    onConnect: createOnConnect([
      sessionMiddleware,
      passportMiddleware,
      passportSessionMiddleware,
    ]),  
   },
});

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

1reaction
jkettmanncommented, May 20, 2020

Thanks for this issue. Can you reproduce this issue in an example repo or codesandbox? That would be very helpful

0reactions
jpbidalcommented, Mar 31, 2021

Hello! I had the same situation like @raymclee @jkettmann My buildContext had no connection param, that was the problem. I tried it after read your comment and my credentials were loaded successfully.

@raymclee the change must be:

const server = new ApolloServer({
  schema,
  // see new connection param
  context: ({ req, res, connection }) => buildContext({ req, res, connection, prisma, pubsub }),
  playground: {
    settings: {
      "request.credentials": "include",
    },
  },
  subscriptions: {
    // @ts-ignore
    onConnect: createOnConnect([
      sessionMiddleware,
      passportMiddleware,
      passportSessionMiddleware,
    ]),  
   },
});

P.S.=Thank you Johannes for this library, and congrats for your great job. Maybe you can add the connection param to the subscription section’s tutorial

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subscriptions - Apollo GraphQL Docs
When Apollo Client executes the OnCommentAdded subscription, it establishes a connection to your GraphQL server and listens for response data. Unlike with a ......
Read more >
How to restart connection with new connection params? #171
A simple solution for this issue is to use a function instead of object for connectionParams , and the transport will call the...
Read more >
How to create subscriptions (using on_behalf_of parameter ...
Hence, the solution is to use a on_behalf_of=connected_account_id parameter, which is covered in the docs. The problem is that stripe.
Read more >
Stripe API reference – Subscriptions – curl
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries....
Read more >
Documentation: 15: CREATE SUBSCRIPTION - PostgreSQL
CREATE SUBSCRIPTION subscription_name CONNECTION ' conninfo ' PUBLICATION publication_name [, ...] [ WITH ( subscription_parameter [= value ] [, ... ] ) ] ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found