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

TypeDefine issues with formatResponse and ApolloServer #3590

Closed
tracy-liucui opened this issue Dec 9, 2019 · 2 comments
Closed

TypeDefine issues with formatResponse and ApolloServer #3590

tracy-liucui opened this issue Dec 9, 2019 · 2 comments

Comments

@tracy-liucui
Copy link

Currently, I encountered some type errors with apollo-server package.

  1. For theformatResponse typeDefine, response can be null, but the returned type doesn't accept null

    formatResponse?: (
    response: GraphQLResponse | null,
    requestContext: GraphQLRequestContext<TContext>,
    ) => GraphQLResponse

  2. Get incompatible error when using custom context type because the ApolloServer is not a generic.

Here is the example:

interface Context {
  foo: string
}

const formatResponse: GraphQLOptions<Context>['formatResponse'] = (
  response
) => response //<-- 1. error: null is not assignable to 'GraphQLResponse'

const server = new ApolloServer({
  formatResponse, //<-- 2. error: Property 'foo' is missing in type '{}' but required in type 'Context'
})
@Markus-ipse
Copy link

I just updated from 2.25.2 to 3.3.0 (I know I am late to the 3.x party) and now formatResponse no longer complain about possibly returning null.

@glasser
Copy link
Member

glasser commented Sep 29, 2021

As @Markus-ipse says, the first concern was fixed earlier this year (#5089, v2.23.0).

If the second concern is still an issue, please file a new issue including a full reproduction (eg starting with git clone or using codesandbox.io) demonstrating it.

@glasser glasser closed this as completed Sep 29, 2021
@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

3 participants