-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix __typename addition for InlineFragments (#1286)
* Fix __typename addition for InlineFragments We need operation registration's __typename adding to match how Apollo Client does this in order for query hashes to match. In order to achieve parity here, I've added the __typename field to InlineFragments as well. While the __typename on an interface may be redundant (see new tests for example), it's also a safer change for me to recommend than anything within Apollo Client. * Update changelog * Ignore test files in config * Update string literals to use Kind
- Loading branch information
1 parent
8e3efb5
commit f4a5c8d
Showing
4 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/apollo-language-server/src/utilities/__tests__/graphql.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import gql from "graphql-tag"; | ||
import { print } from "graphql"; | ||
import { withTypenameFieldAddedWhereNeeded } from "../graphql"; | ||
|
||
describe("withTypenameFieldAddedWhereNeeded", () => { | ||
it("properly adds __typename to each selectionSet", () => { | ||
const query = gql` | ||
query Product { | ||
product { | ||
sku | ||
color { | ||
id | ||
value | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const withTypenames = withTypenameFieldAddedWhereNeeded(query); | ||
|
||
expect(print(withTypenames)).toMatchInlineSnapshot(` | ||
"query Product { | ||
product { | ||
__typename | ||
sku | ||
color { | ||
__typename | ||
id | ||
value | ||
} | ||
} | ||
} | ||
" | ||
`); | ||
}); | ||
|
||
it("adds __typename to InlineFragment nodes (as ApolloClient does)", () => { | ||
const query = gql` | ||
query CartItems { | ||
product { | ||
items { | ||
... on Table { | ||
material | ||
} | ||
... on Paint { | ||
color | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const withTypenames = withTypenameFieldAddedWhereNeeded(query); | ||
|
||
expect(print(withTypenames)).toMatchInlineSnapshot(` | ||
"query CartItems { | ||
product { | ||
__typename | ||
items { | ||
__typename | ||
... on Table { | ||
__typename | ||
material | ||
} | ||
... on Paint { | ||
__typename | ||
color | ||
} | ||
} | ||
} | ||
} | ||
" | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters