Skip to content

Commit

Permalink
FIX: fixed potential bug in info object that is passed to onTypeConfl… (
Browse files Browse the repository at this point in the history
#3216)

* FIX: fixed potential bug in info object that is passed to onTypeConflict callback  and caused right and left to reference the same object.

* Added a test that checks if info object passed to the onTypeConflict callback contains right and left objects with properties that are not equal.

* Removed unnecessary async from onTypeConflict test

* Added a changeset
  • Loading branch information
OLRG authored Jul 25, 2021
1 parent edb58c7 commit 91155ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-items-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/stitch': patch
---

Fixed issue with stitchSchemas function returning info object with left.subschema and right.subschema referencing the same object
4 changes: 2 additions & 2 deletions packages/stitch/src/typeCandidates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ function onTypeConflictToCandidateSelector<TContext = Record<string, any>>(
transformedSubschema: prev.transformedSubschema,
},
right: {
subschema: prev.subschema,
transformedSubschema: prev.transformedSubschema,
subschema: next.subschema,
transformedSubschema: next.transformedSubschema,
},
});
if (prev.type === type) {
Expand Down
12 changes: 12 additions & 0 deletions packages/stitch/tests/alternateStitchSchemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,18 @@ describe('onTypeConflict', () => {
const result2 = await graphql(stitchedSchema, '{ test1 { fieldC } }');
expect(result2.data).toBeUndefined();
});

test('returns info.left and info.right properties that are not equal', () => {
stitchSchemas({
subschemas: [schema1, schema2],
mergeTypes: false,
onTypeConflict: (left, _right, info) => {
expect(info?.right.subschema !== info?.left.subschema).toBe(true);
expect(info?.right.transformedSubschema !== info?.left.transformedSubschema).toBe(true);
return left;
}
});
});
});

describe('basic type merging', () => {
Expand Down

0 comments on commit 91155ab

Please sign in to comment.