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

Typing issues with "ApolloServerExpressConfig" in version 2.4.8 #2469

Closed
stefanholzapfel opened this issue Mar 18, 2019 · 6 comments
Closed
Labels
🪲 bug 🧬 typings Relates to TypeScript changes or improvements.

Comments

@stefanholzapfel
Copy link
Contributor

Since upgrading from apollo-server-express 2.4.2 to 2.4.8 I have two typing issues with the ApolloServer config used in the constructor:

1.) I can't use the "formatError" from the apollo-erros package (version1.9.0) anymore. I get this error:

Type '(error: any, returnNull?: boolean) => ErrorInfo' is not assignable to type '(error: GraphQLError) => GraphQLFormattedError'.   Type 'ErrorInfo' is not assignable to type 'GraphQLFormattedError'.     Property 'locations' is optional in type 'ErrorInfo' but required in type 'GraphQLFormattedError'.

2.) I can't access the "connection" parameter anymore from the context creation function (it returns an "ExpressContext"). It's not a recognized parameter anymore.

But in the docs it's still the propesed way to create context for subscriptions: https://www.apollographql.com/docs/apollo-server/features/subscriptions.html#Context-with-Subscriptions

I have to stick with version 2.4.2 until this problem is resolved.

Thanks for any help.

@stefanholzapfel
Copy link
Contributor Author

Any chance that issue will be addressed? Thanks!

@stefanholzapfel
Copy link
Contributor Author

@abernix
Hi!
Can you please review my pullrequest at #2959 concerning this issue? It's just a changed typing.

Thx!

@abernix abernix added 🧬 typings Relates to TypeScript changes or improvements. 🪲 bug labels Jul 4, 2019
@abernix
Copy link
Member

abernix commented Jul 4, 2019

Looks like you've reported two separate problems in one issue. In the future, it's best to separate those out, particularly since the PR you opened to fix them only fixes one of the two!

That said, could you please provide a small, runnable reproduction (even if it crashes) which demonstrates this. I haven't run into this problem yet, but I'm worried that adding an additional non-required connection property to this interface could be a breaking change for some. That way we can confirm the problem you're reporting is fixed.

Thanks!

@stefanholzapfel
Copy link
Contributor Author

stefanholzapfel commented Jul 4, 2019

@abernix You are right separating would be better, sorry for that :). I think we can forget about the formatErrors problem anyway, since apollo-errors package seems deprecated.

Concerning the pull request:

You can take the example from the docs:
https://www.apollographql.com/docs/apollo-server/features/subscriptions.html#Context-with-Subscriptions

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

      return { token };
    }
  },
});

The current typings won't allow that because they don't know the connection parameter. It's not an error (in javascript it works fine), but the typescript transpiler won't let you pass.

@keeganstothert
Copy link

keeganstothert commented Jul 10, 2019

any update on this? I tried to add the fix from the PR

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

idk where ExecutionParams was coming from and it doesn't exist

@abernix
Copy link
Member

abernix commented Aug 8, 2019

Should have been fixed by #2959!

@abernix abernix closed this as completed Aug 8, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🪲 bug 🧬 typings Relates to TypeScript changes or improvements.
Projects
None yet
Development

No branches or pull requests

3 participants