graphql-tools
graphql-tools copied to clipboard
Interference between `RenameInputObjectFields` transforms
Issue workflow progress
Progress of the issue based on the 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
Could you create a PR with this test? Maybe you can try to fix that as well?
Thanks for the quick response. I opened a PR with two tests, one that passes and a similar one that does not. I spent some time trying to debug, but was not able to identify or fix the issue.