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

Graphql MockServer Resolver Preservation #253

Open
cchen9299 opened this issue Aug 30, 2024 · 1 comment
Open

Graphql MockServer Resolver Preservation #253

cchen9299 opened this issue Aug 30, 2024 · 1 comment

Comments

@cchen9299
Copy link
Contributor

Motivation:
With the introduction of [email protected] and [email protected], the underlying @graphql-tools/mock went from v2 to v8. Through this change, mocked resolver behaviors changed and for our teams, specifically the ability to key into request information to return corresponding mock data.

To elaborate, given there is a feature where the UI displays email information of multiple users and there is an operation that fetches user's email. The UI can either be making aliased calls or multiple calls to graphql with the user's ID expecting that the corresponding data is returned for each user ID. Previously we were able to mock the resolver dynamically with the first argument in the mocked resolver. But with graphql-toolsV8 by default, those resolvers are seemingly flattened and no longer provide the request information.

const { graphql } = require('parrot-friendly')
const { getUserEmail } = require('./helper');

...

it('US - CARD & BANKING (multi) - Mobile Phone - security update failure', () => {
  graphql('/graphql', schema, {
    Query: () => ({
      // resolver args are now undefine
      getEmail: ({ userID }) => getUserEmail(userID),
    }),
  });
});

The only solution that I've found so far is to update the preserveResolver value to true (the third argument passed to mockServer of @graphql-tools/mock). I am then able to pass in makeExecutableSchema({}) of the basically the same resolver to see the request information again. (Basically the same because graphql-tools have since move the request variable to the second argument ie., getEmail: (_, { userID }) => getUserEmail(userID),)

Will be opening a PR for this for review.

Copy link

Thanks for opening your first issue. Pull requests are always welcome!

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