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

Type checking issues with getClient.mutate() #222

Open
jeffstephens opened this issue Mar 1, 2024 · 0 comments
Open

Type checking issues with getClient.mutate() #222

jeffstephens opened this issue Mar 1, 2024 · 0 comments

Comments

@jeffstephens
Copy link

jeffstephens commented Mar 1, 2024

Hi there,

We've been using this project and it has been excellent for the most part - greatly appreciated.

There is one issue we've been running into - getClient().mutate() calls don't automatically type-check input variables. getClient() is the RSC implementation from the docs:

export const { getClient } = registerApolloClient(() => {
// ...

With our graphql-codegen-generated types, the return types all Just Work, but variables are only type-checked if we explicitly set both types in the mutate<T, T> generic arguments. Otherwise, it infers the type from the provided variables irrespective of the GraphQL schema, causing run-time errors rather than build-time.

Here's an example. The return type is correctly set.

return getClient().mutate({
  mutation: MESSAGE_MARK_READ,
  variables: {
    input: {
      messageId,
      test: true, // <-- this is not in the mutation input in GQL, but no type error
    },
  },
});

After adding types as mutate<MyMutation, MyMutationVariables({, an error is thrown for test.

However, if I then move input into a new variable and pass it into the mutation, the type checking breaks down again, even with the explicit types specified. I'm not sure if these issues are related, but it seems likely.

Based on the hook-based useMutation, I'd expect all this to work automatically in both of the cases above. Please let me know if I can provide any more information or help.

Thank you for your time!

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

No branches or pull requests

1 participant