Skip to content

fix: support nullable GraphQL queries #2403

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

Merged
merged 4 commits into from
May 18, 2025

Conversation

huuyafwww
Copy link
Contributor

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?

@kettanaito kettanaito changed the title feat: support nullable graphql query fix: support nullable GraphQL queries May 17, 2025
@kettanaito kettanaito merged commit 594e8ca into mswjs:main May 18, 2025
25 of 26 checks passed
@kettanaito
Copy link
Member

Released: v2.8.4 🎉

This has been released in v2.8.4!

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants