-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix type policy inheritance involving fuzzy possibleTypes
#10633
Merged
benjamn
merged 5 commits into
release-3.8
from
fix-typePolicies-inheritance-involving-fuzzy-possibleTypes
Mar 9, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ff35462
Test combining fuzzy possibleTypes with keyFields inheritance.
benjamn 08d52a6
Fix the fuzzy possibleTypes + keyFields inheritance test.
benjamn d4cab18
Add .changeset/ entry file for PR #10633.
benjamn 08549be
Bump bundlesize limit to 34.1KB (currently 33.98KB).
benjamn f9ab7a2
Test full cache.extract() at end of test.
benjamn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@apollo/client': patch | ||
--- | ||
|
||
Fix type policy inheritance involving fuzzy `possibleTypes` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -627,6 +627,182 @@ describe("type policies", function () { | |
})).toBe('DeathAdder:{"tagId":"LethalAbacus666"}'); | ||
}); | ||
|
||
it("typePolicies can be inherited from supertypes with fuzzy possibleTypes", () => { | ||
const cache = new InMemoryCache({ | ||
possibleTypes: { | ||
EntitySupertype: [".*Entity"], | ||
}, | ||
typePolicies: { | ||
Query: { | ||
fields: { | ||
coworkers: { | ||
merge(existing, incoming) { | ||
return existing ? existing.concat(incoming) : incoming; | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
// The point of this test is to ensure keyFields: ["uid"] can be | ||
// registered for all __typename strings matching the RegExp /.*Entity/, | ||
// without manually enumerating all of them. | ||
EntitySupertype: { | ||
keyFields: ["uid"], | ||
}, | ||
}, | ||
}); | ||
|
||
type Coworker = { | ||
__typename: "CoworkerEntity" | "ManagerEntity"; | ||
uid: string; | ||
name: string; | ||
} | ||
|
||
const query: TypedDocumentNode<{ | ||
coworkers: Coworker[]; | ||
}> = gql` | ||
query { | ||
coworkers { | ||
uid | ||
name | ||
} | ||
} | ||
`; | ||
|
||
cache.writeQuery({ | ||
query, | ||
data: { | ||
coworkers: [ | ||
{ __typename: "CoworkerEntity", uid: "qwer", name: "Alessia" }, | ||
{ __typename: "CoworkerEntity", uid: "asdf", name: "Jerel" }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm honored to make it into a test 😆 |
||
{ __typename: "CoworkerEntity", uid: "zxcv", name: "Lenz" }, | ||
{ __typename: "ManagerEntity", uid: "uiop", name: "Jeff" }, | ||
], | ||
}, | ||
}); | ||
|
||
expect(cache.extract()).toEqual({ | ||
ROOT_QUERY: { | ||
__typename: "Query", | ||
coworkers: [ | ||
{ __ref: 'CoworkerEntity:{"uid":"qwer"}' }, | ||
{ __ref: 'CoworkerEntity:{"uid":"asdf"}' }, | ||
{ __ref: 'CoworkerEntity:{"uid":"zxcv"}' }, | ||
{ __ref: 'ManagerEntity:{"uid":"uiop"}' }, | ||
], | ||
}, | ||
'CoworkerEntity:{"uid":"qwer"}': { | ||
__typename: "CoworkerEntity", | ||
uid: "qwer", | ||
name: "Alessia", | ||
}, | ||
'CoworkerEntity:{"uid":"asdf"}': { | ||
__typename: "CoworkerEntity", | ||
uid: "asdf", | ||
name: "Jerel", | ||
}, | ||
'CoworkerEntity:{"uid":"zxcv"}': { | ||
__typename: "CoworkerEntity", | ||
uid: "zxcv", | ||
name: "Lenz", | ||
}, | ||
'ManagerEntity:{"uid":"uiop"}': { | ||
__typename: "ManagerEntity", | ||
uid: "uiop", | ||
name: "Jeff", | ||
}, | ||
}); | ||
|
||
interface CoworkerWithAlias extends Omit<Coworker, "uid"> { | ||
idAlias: string; | ||
} | ||
|
||
const queryWithAlias: TypedDocumentNode<{ | ||
coworkers: CoworkerWithAlias[]; | ||
}> = gql` | ||
query { | ||
coworkers { | ||
idAlias: uid | ||
name | ||
} | ||
} | ||
`; | ||
|
||
expect(cache.readQuery({ query: queryWithAlias })).toEqual({ | ||
coworkers: [ | ||
{ __typename: "CoworkerEntity", idAlias: "qwer", name: "Alessia" }, | ||
{ __typename: "CoworkerEntity", idAlias: "asdf", name: "Jerel" }, | ||
{ __typename: "CoworkerEntity", idAlias: "zxcv", name: "Lenz" }, | ||
{ __typename: "ManagerEntity", idAlias: "uiop", name: "Jeff" }, | ||
], | ||
}); | ||
|
||
cache.writeQuery({ | ||
query: queryWithAlias, | ||
data: { | ||
coworkers: [ | ||
{ __typename: "CoworkerEntity", idAlias: "hjkl", name: "Martijn" }, | ||
{ __typename: "ManagerEntity", idAlias: "vbnm", name: "Hugh" }, | ||
], | ||
}, | ||
}); | ||
jerelmiller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
expect(cache.readQuery({ query })).toEqual({ | ||
coworkers: [ | ||
{ __typename: "CoworkerEntity", uid: "qwer", name: "Alessia" }, | ||
{ __typename: "CoworkerEntity", uid: "asdf", name: "Jerel" }, | ||
{ __typename: "CoworkerEntity", uid: "zxcv", name: "Lenz" }, | ||
{ __typename: "ManagerEntity", uid: "uiop", name: "Jeff" }, | ||
{ __typename: "CoworkerEntity", uid: "hjkl", name: "Martijn" }, | ||
{ __typename: "ManagerEntity", uid: "vbnm", name: "Hugh" }, | ||
], | ||
}); | ||
|
||
expect(cache.extract()).toEqual({ | ||
ROOT_QUERY: { | ||
__typename: "Query", | ||
coworkers: [ | ||
{ __ref: 'CoworkerEntity:{"uid":"qwer"}' }, | ||
{ __ref: 'CoworkerEntity:{"uid":"asdf"}' }, | ||
{ __ref: 'CoworkerEntity:{"uid":"zxcv"}' }, | ||
{ __ref: 'ManagerEntity:{"uid":"uiop"}' }, | ||
{ __ref: 'CoworkerEntity:{"uid":"hjkl"}' }, | ||
{ __ref: 'ManagerEntity:{"uid":"vbnm"}' }, | ||
], | ||
}, | ||
'CoworkerEntity:{"uid":"qwer"}': { | ||
__typename: "CoworkerEntity", | ||
uid: "qwer", | ||
name: "Alessia", | ||
}, | ||
'CoworkerEntity:{"uid":"asdf"}': { | ||
__typename: "CoworkerEntity", | ||
uid: "asdf", | ||
name: "Jerel", | ||
}, | ||
'CoworkerEntity:{"uid":"zxcv"}': { | ||
__typename: "CoworkerEntity", | ||
uid: "zxcv", | ||
name: "Lenz", | ||
}, | ||
'ManagerEntity:{"uid":"uiop"}': { | ||
__typename: "ManagerEntity", | ||
uid: "uiop", | ||
name: "Jeff", | ||
}, | ||
'CoworkerEntity:{"uid":"hjkl"}': { | ||
__typename: "CoworkerEntity", | ||
uid: "hjkl", | ||
name: "Martijn", | ||
}, | ||
'ManagerEntity:{"uid":"vbnm"}': { | ||
__typename: "ManagerEntity", | ||
uid: "vbnm", | ||
name: "Hugh", | ||
}, | ||
}); | ||
}); | ||
|
||
describe("field policies", function () { | ||
it(`can filter arguments using keyArgs`, function () { | ||
const cache = new InMemoryCache({ | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this may still look like a lot of boilerplate, the key point is that we don't need any mention of subtypes like
CoworkerEntity
orManagerEntity
in this configuration code.