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

feat: support nullable graphql query #2403

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

huuyafwww
Copy link

Hello, thank you for developing this wonderful library called msw. I am using msw in my graphql project. There I have a Query with nullable return value.
And I generate that type using graphql-codegen.
Here is an example of the generated type.

export type Maybe<T> = T | null;

export type IQuery = {
  __typename?: 'Query';
  authUser: Maybe<IUser>;
  user: Maybe<IUser>;
};

And I tried to use this query type which may return null in graphql.query and graphql.mutation.

import { graphql } from 'msw';

graphql.query<IQuery['authUser'], /* variable type */>(queryName, () => {});
graphql.mutation</* nullable mutation */, /* variable type */>(queryName, () => {});

Then I got a type error that nullable queries and mutations are not supported.

I would like to have the actual value returned by a query or mutation set strictly as a type in mock as well.
Therefore, I have modified GraphQLQuery to allow null.
What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant