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

Property 'connection' does not exist on type 'ExpressContext' #3208

Closed
alexbjorlig opened this issue Aug 26, 2019 · 7 comments
Closed

Property 'connection' does not exist on type 'ExpressContext' #3208

alexbjorlig opened this issue Aug 26, 2019 · 7 comments

Comments

@alexbjorlig
Copy link

I am trying to follow this guide, on setting up subscriptions with apollo-server-express@2.9.0, but the middleware connection check is giving a typescript problem:

Property 'connection' does not exist on type 'ExpressContext'

The code snippet:

const server = new ApolloServer({
  schema,
  context: async ({ req, connection }) => { // Typescript error here
    if (connection) {
      // check connection for metadata
      return connection.context;
    } else {
      // check from req
      const token = req.headers.authorization || "";

      return { token };
    }
  },
});

Currently, I am doing this workaround: const { req, connection } = v as any;

@abernix
Copy link
Member

abernix commented Aug 26, 2019

I believe this was meant to be be fixed via #2959. Is it possible you have multiple versions of apollo-server-express in your project? (You can run npm ls apollo-server-express or yarn ls apollo-server-express to find the answer).

@stefanholzapfel @Siyfion Did you find that the typing problem with the connection property was resolved after #2959?

@abernix
Copy link
Member

abernix commented Aug 26, 2019

@dauledk Also, whether or not it's the exact steps in the guide, including a runnable reproduction would be helpful.

@alexbjorlig
Copy link
Author

Running npm ls apollo-server-express only gave 2.9.0. Looking around here in the github repo, are we not missing connection from this line here?

@stefanholzapfel
Copy link
Contributor

stefanholzapfel commented Aug 26, 2019

@abernix @dauledk Just upgraded from 2.8.1 to 2.9.0 without any problems. Using context like this:

context: async ({ req, connection }) => {}

ExpressContext still contains the connection property:

export interface ExpressContext {
  req: express.Request;
  res: express.Response;
  connection?: ExecutionParams;
}

@alexbjorlig
Copy link
Author

After closing VS code and opening again, the error is gone. Thanks for the help - and sorry for the inconvenience 😅

@abernix
Copy link
Member

abernix commented Sep 4, 2019

@dauledk No inconvenience; thanks for following up! (And thank you @stefanholzapfel for jumping in!)

@MichaelHindley
Copy link

@abernix when working with Subscriptions, you get an ExpressContext that has connection but no req or res. Shouldn't they hence be nullable?

image

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants