question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mutations with no return value stall forever

See original GitHub issue

When a resolve callback’s return type is either:

  • Promise<void>
  • Promise<null>
  • Promise<undefined

tRPC doesn’t ever close the response stream, thus, stalling the client indefinitely.

The following code doesn’t work:

trpc.router<Context>()
  .mutation("update", {
    input: z.object({ id: z.string() }),
    resolve: async ({ ctx, input }): Promise<void> => {
      await updateSection(input);
      // `return undefined` or `return null` wouldn’t solve the case
    },
  });

But the following return value change does the trick:

trpc.router<Context>()
  .mutation("update", {
    input: z.object({ id: z.string() }),
    resolve: async ({ ctx, input }): Promise<{ [key: string]: never }> => {
      await updateSection(input);
      return {};
    },
  });

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
simonedelmanncommented, Jun 15, 2021

@KATT This is not related to #512 , but might be an indication for the same problem. I think we should generally add tests for these non-defined cases, so we can catch bugs like this or like #512. (We need tests for undefined/null/{}/void input and output.) I just saw, you’ve already added a test now. If you need help, I can add some more tests regarding that later today.

1reaction
KATTcommented, Jun 15, 2021

@simonedelmann happy if you can review the PR ❤️ and challenge the way I did it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to not return any data when using a GraphQL ...
I have several GraphQL queries and mutations, now I'm trying to implement a delete mutation without returning any data: type Mutation{ ...
Read more >
Mutations in Apollo Client - Apollo GraphQL Docs
To refetch a query from onQueryUpdated , call return observableQuery.refetch() , as shown above. Otherwise, no return value is required. If a refetched...
Read more >
Guide to Genetics - Space Station 13 Wiki
Through the Gene Booth, you can share Mutations without having to stray from the console. When you access an occupant's Mutations or Stored ......
Read more >
how to write a mutation schema which returns null? · Issue #277
I am trying to write a schema with a single mutation, which should return null. Problem is when I try to do that,...
Read more >
Best practices for GraphQL mutations - Fauna
GraphQL mutations are used to modify data in your API. ... Return type specifies that this mutation must always have a return value....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found