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

TypeScript error using passthrough() in GraphQL mock #1977

Closed
4 tasks done
callummr opened this issue Jan 18, 2024 · 1 comment · Fixed by #2002
Closed
4 tasks done

TypeScript error using passthrough() in GraphQL mock #1977

callummr opened this issue Jan 18, 2024 · 1 comment · Fixed by #2002
Assignees
Labels
bug Something isn't working scope:node Related to MSW running in Node scope:typescript

Comments

@callummr
Copy link

callummr commented Jan 18, 2024

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 18 or higher

Node.js version

20.5.1

Reproduction repository

https://codesandbox.io/p/sandbox/msw-gql-passthrough-typeerror-jz9s6m?file=%2Fsrc%2Fmsw.ts

Reproduction steps

Open msw.ts. Observe TS errors.

Current behavior

TypeScript error when trying to return passthrough() in a GraphQL handler.

const operationHandler = graphql.operation(() => {
  return passthrough();
});
Argument of type '() => Response' is not assignable to parameter of type 'ResponseResolver<GraphQLResolverExtras<GraphQLVariables>, null, GraphQLResponseBody<Record<string, any>>>'.
  Type 'Response' is not assignable to type 'AsyncResponseResolverReturnType<GraphQLResponseBody<Record<string, any>>>'.
    Property '[bodyType]' is missing in type 'Response' but required in type 'StrictResponse<GraphQLResponseBody<Record<string, any>>>'.typescript(2345)

Can be worked around by casting the passthrough type:

const graphqlPassthrough = passthrough as () => ReturnType<
  typeof HttpResponse.json<{ data: any }>
>;

const operationHandler = graphql.operation(() => {
  return graphqlPassthrough();
});

Expected behavior

passthrough() can be returned in graphql mocks, as it can in http mocks.

@callummr callummr added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node labels Jan 18, 2024
@kettanaito kettanaito self-assigned this Jan 28, 2024
@kettanaito kettanaito added scope:typescript and removed needs:triage Issues that have not been investigated yet. labels Jan 28, 2024
@kettanaito
Copy link
Member

Released: v2.1.6 🎉

This has been released in v2.1.6!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working scope:node Related to MSW running in Node scope:typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants