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

Pass fieldArgs to value function #5730

Merged
merged 2 commits into from Jan 22, 2024
Merged

Pass fieldArgs to value function #5730

merged 2 commits into from Jan 22, 2024

Conversation

zyzo
Copy link
Contributor

@zyzo zyzo commented Nov 28, 2023

Description

Fix #4497. This allows for finer-grained mocking with mocked data depending on field arguments.

const store = createMockStore({
    schema,
    mocks: {
      User: () => {
        return {
          name: ({ format }: { format: string }) =>
            format === 'fullName' ? 'Alexandre the Great' : 'Alex',
        };
      },
    },
  });

store.get('User', '123', 'name', { format: 'fullName' }))
// Alexandre the Great
store.get('User', '123', 'name', { format: 'shortName ' }))
// Alex

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • store.spec.ts: should pass field args to value getter function

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests and linter rules pass locally with my changes

Copy link

changeset-bot bot commented Nov 28, 2023

🦋 Changeset detected

Latest commit: 36d20dc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphql-tools/mock Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ardatan ardatan merged commit 694d540 into ardatan:master Jan 22, 2024
27 of 28 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants