ardatan / ardatan/graphql-tools

Can't mock nested field resolvers

Open
#4,848 0 comments 9 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5.4k
Forks
830
Avg merge
10h 59m
Merged PRs (30d)
45

Description

### Issue workflow progress

_Progress of the issue based on the [Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-contributor-workflow)_

- [x] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
> Make sure to fork this template and run `yarn generate` in the terminal.
>
> Please make sure the GraphQL Tools package versions under `package.json` matches yours.
- [x] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review

---

**Describe the bug**

When mocking a nested root query, I can override any simple field, but overriding resolver fields doesn't work.

**To Reproduce**

[Here is a test showing the problem](https://github.com/sunesimonsen/graphql-tools/blob/ssimonsen/mock-nested-root-query/packages/mock/tests/mocking-compatibility.spec.ts#L580-L611)

You can run the test in my fork, or just copy over the test.

**Expected behavior**

I expect `returnStringArgument` to have the value `Overridden`, but I get the default string value `Hello World`.

**Environment:**

- OS: OSX
- `@graphql-tools/mock`:
- NodeJS: v16.18.0

**Additional context**

I'm trying to fix a problem we are seeing in another tool [graphql-fakester](https://github.com/sunesimonsen/graphql-fakester/issues/103)

Contributor guide

Open the contributing guide

Research direction

Start with the reproduction in packages/mock/tests/mocking-compatibility.spec.ts, specifically the test linked at lines 580-611, and run it after copying it from the referenced fork. Done means the nested resolver override makes returnStringArgument equal "Overridden" instead of the default "Hello World".

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.