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

types: make MockResolver recursive with ResolverMap #4

Merged
merged 2 commits into from
Jan 12, 2021

Conversation

derrh
Copy link
Contributor

@derrh derrh commented Jan 11, 2021

In projects with strict prohibitions against inferred any types, resolver maps that include Query or Mutation resolvers will result in type errors unless they are explicitly typed.

The following code results in a TypeScript error if you do not manually specify params and return types for the resolver

  mocks: {
    Query: () => ({
      user: (_parent, args) => ({
        userId: args.userId,
      }),
    }),
  }

Error:
image

@donovanhiland
Copy link
Collaborator

@derrh I think this is a bigger problem than just with Query and Mutation types. If you access resolver arguments in any inline resolver this will happen. It's kind of a verbose problem to solve because the type-system needs to be aware of the entire schema to provide accurate types.

I plan on looking into a way to type the mocker based on the user's schema but for now maybe you can just pass _parent: any explicitly to make typescript happy?

@derrh derrh closed this Jan 11, 2021
@derrh derrh reopened this Jan 11, 2021
@donovanhiland donovanhiland changed the title Small update adding Query and Mutation to the ResolverMap types: make MockResolver recursive with ResolverMap Jan 12, 2021
@donovanhiland donovanhiland merged commit 767201a into ravnhq:master Jan 12, 2021
@donovanhiland
Copy link
Collaborator

🎉 This PR is included in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants