ardatan / ardatan/graphql-tools

Interference between `RenameInputObjectFields` transforms

Open
#5,091 2 comments 0 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)_

- [ ] 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**

`RenameInputObjectFields` transforms seem to be interfering with each other resulting in field names not transforming as expected. The bug has not been identified specifically, but a failing test is provided below which is a modification of the first test in `packages/wrap/tests/transformRenameInputObjectFields.test.ts`. The test below passes when static args are provided in the document.

```
test('renaming with arguments works', async () => {
const schema = makeExecutableSchema({
typeDefs: /* GraphQL */ `
input InputObject {
field1: String
field2: String
}

type OutputObject {
field1: String
field2: String
}

type Query {
test(argument: InputObject): OutputObject
}
`,
resolvers: {
Query: {
test: (_root, args) => {
return args.argument;
},
},
},
});

const transformedSchema = wrapSchema({
schema,
transforms: [
new RenameInputObjectFields((typeName, fieldName) => {
if (typeName === 'InputObject' && fieldName === 'field2') {
return 'field3';
}
}),
new RenameInputObjectFields((typeName, fieldName) => {
if (typeName === 'InputObject' && fieldName === 'field1') {
return 'field0';
}
}),
],
});

const query = /* GraphQL */ `
query ($argument: InputObject) {
test(argument: $argument) {
field1
field2
}
}
`;

const result = await execute({
schema: transformedSchema,
document: parse(query),
variableValues: { argument: { field0: "field1", field3: "field2" } },
});
if (isIncrementalResult(result)) throw Error('result is incremental');
assertSome(result.data);
const testData: any = result.data['test'];
expect(testData.field1).toBe('field1');
expect(testData.field2).toBe('field2');
})`
```

**To Reproduce**
Steps to reproduce the behavior:

Run the failing test provided above.

**Expected behavior**

The fields should be renamed and the test should pass.

**Environment:**

- OS: Ubuntu 22.04.2 LTS
- `@graphql-tools/wrap`: 9.3.7
- NodeJS: 18.12.0

Contributor guide

Open the contributing guide

Research direction

Run the failing test in packages/wrap/tests/transformRenameInputObjectFields.test.ts, starting from the modified “renaming with arguments works” case. Trace the two RenameInputObjectFields transforms and variable handling; done means both field renames are applied and the test returns field1 and field2 as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.