Skip to content

Commit

Permalink
Merged types should allow query of __typename field without crashin…
Browse files Browse the repository at this point in the history
…g query (#1629)

* fix(merge types __typename): add test to trigger issue

* don't refetch __typename

Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
  • Loading branch information
2 people authored and ardatan committed Jun 10, 2020
1 parent 5b93e0e commit 753ea04
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 2 additions & 3 deletions .github/FUNDING.yml
@@ -1,3 +1,2 @@
# These are supported funding model platforms

patreon: ardatan # Replace with a single Patreon username
patreon: ardatan
github: ardatan
4 changes: 4 additions & 0 deletions packages/delegate/src/mergeFields.ts
Expand Up @@ -40,6 +40,10 @@ function buildDelegationPlan(

const delegationMap: Map<SubschemaConfig, Array<SelectionNode>> = new Map();
originalSelections.forEach(selection => {
if (selection.name.value === '__typename') {
return;
}

// 2a. use uniqueFields map to assign fields to subschema if one of possible subschemas

const uniqueSubschema: SubschemaConfig = uniqueFields[selection.name.value];
Expand Down
2 changes: 2 additions & 0 deletions packages/stitch/tests/typeMerging.test.ts
Expand Up @@ -74,6 +74,7 @@ describe('merging using type merging', () => {
const query = `
query {
userById(id: 5) {
__typename
chirps {
id
textAlias: text
Expand All @@ -88,6 +89,7 @@ describe('merging using type merging', () => {
const result = await graphql(stitchedSchema, query);

expect(result.errors).toBeUndefined();
expect(result.data.userById.__typename).toBe('User');
expect(result.data.userById.chirps[1].id).not.toBe(null);
expect(result.data.userById.chirps[1].text).not.toBe(null);
expect(result.data.userById.chirps[1].author.email).not.toBe(null);
Expand Down

0 comments on commit 753ea04

Please sign in to comment.