Skip to content
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

Make keyArgs tolerant of optional arguments. #7109

Merged
merged 2 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
- The schema link package (`@apollo/client/link/schema`) will now validate incoming queries against its client-side schema, and return `errors` as a GraphQL server would. <br/>
[@amannn](https://github.com/amannn) in [#7094](https://github.com/apollographql/apollo-client/pull/7094)

- Allow optional arguments in `keyArgs: [...]` arrays for `InMemoryCache` field policies. <br/>
[@benjamn](https://github.com/benjamn) in [#7109](https://github.com/apollographql/apollo-client/pull/7109)

## Apollo Client 3.2.2

## Bug Fixes
Expand Down
372 changes: 372 additions & 0 deletions src/cache/inmemory/__tests__/__snapshots__/policies.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,378 @@ Object {
}
`;

exports[`type policies field policies can include optional arguments in keyArgs 1`] = `
Object {
"Author:{\\"name\\":\\"Nadia Eghbal\\"}": Object {
"__typename": "Author",
"name": "Nadia Eghbal",
"writings:{\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
},
"ROOT_QUERY": Object {
"__typename": "Query",
"author": Object {
"__ref": "Author:{\\"name\\":\\"Nadia Eghbal\\"}",
},
},
}
`;

exports[`type policies field policies can include optional arguments in keyArgs 2`] = `
Object {
"Author:{\\"name\\":\\"Nadia Eghbal\\"}": Object {
"__typename": "Author",
"name": "Nadia Eghbal",
"writings:{\\"a\\":1,\\"b\\":2,\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
},
"ROOT_QUERY": Object {
"__typename": "Query",
"author": Object {
"__ref": "Author:{\\"name\\":\\"Nadia Eghbal\\"}",
},
},
}
`;

exports[`type policies field policies can include optional arguments in keyArgs 3`] = `
Object {
"Author:{\\"name\\":\\"Nadia Eghbal\\"}": Object {
"__typename": "Author",
"name": "Nadia Eghbal",
"writings:{\\"a\\":1,\\"b\\":2,\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"a\\":1,\\"b\\":2}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
},
"ROOT_QUERY": Object {
"__typename": "Query",
"author": Object {
"__ref": "Author:{\\"name\\":\\"Nadia Eghbal\\"}",
},
},
}
`;

exports[`type policies field policies can include optional arguments in keyArgs 4`] = `
Object {
"Author:{\\"name\\":\\"Nadia Eghbal\\"}": Object {
"__typename": "Author",
"name": "Nadia Eghbal",
"writings:{\\"a\\":1,\\"b\\":2,\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"a\\":1,\\"b\\":2}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"b\\":2}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
},
"ROOT_QUERY": Object {
"__typename": "Query",
"author": Object {
"__ref": "Author:{\\"name\\":\\"Nadia Eghbal\\"}",
},
},
}
`;

exports[`type policies field policies can include optional arguments in keyArgs 5`] = `
Object {
"Author:{\\"name\\":\\"Nadia Eghbal\\"}": Object {
"__typename": "Author",
"name": "Nadia Eghbal",
"writings:{\\"a\\":1,\\"b\\":2,\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"a\\":1,\\"b\\":2}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"a\\":3}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"b\\":2}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
},
"ROOT_QUERY": Object {
"__typename": "Query",
"author": Object {
"__ref": "Author:{\\"name\\":\\"Nadia Eghbal\\"}",
},
},
}
`;

exports[`type policies field policies can include optional arguments in keyArgs 6`] = `
Object {
"Author:{\\"name\\":\\"Nadia Eghbal\\"}": Object {
"__typename": "Author",
"name": "Nadia Eghbal",
"writings:{\\"a\\":1,\\"b\\":2,\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"a\\":1,\\"b\\":2}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"a\\":3}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"b\\":2}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
},
"ROOT_QUERY": Object {
"__typename": "Query",
"author": Object {
"__ref": "Author:{\\"name\\":\\"Nadia Eghbal\\"}",
},
},
}
`;

exports[`type policies field policies can include optional arguments in keyArgs 7`] = `
Object {
"Author:{\\"name\\":\\"Nadia Eghbal\\"}": Object {
"__typename": "Author",
"name": "Nadia Eghbal",
"writings:{\\"a\\":1,\\"b\\":2,\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"a\\":1,\\"b\\":2}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"a\\":3}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"b\\":2}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"b\\":4}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
},
"ROOT_QUERY": Object {
"__typename": "Query",
"author": Object {
"__ref": "Author:{\\"name\\":\\"Nadia Eghbal\\"}",
},
},
}
`;

exports[`type policies field policies can include optional arguments in keyArgs 8`] = `
Object {
"Author:{\\"name\\":\\"Nadia Eghbal\\"}": Object {
"__typename": "Author",
"name": "Nadia Eghbal",
"writings": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"a\\":1,\\"b\\":2,\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"a\\":1,\\"b\\":2}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"a\\":3}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"b\\":2}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"b\\":4}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{\\"type\\":\\"Book\\"}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
"writings:{}": Array [
Object {
"__typename": "Book",
"isbn": "0578675862",
"title": "Working in Public: The Making and Maintenance of Open Source Software",
},
],
},
"ROOT_QUERY": Object {
"__typename": "Query",
"author": Object {
"__ref": "Author:{\\"name\\":\\"Nadia Eghbal\\"}",
},
},
}
`;

exports[`type policies field policies read, merge, and modify functions can access options.storage 1`] = `
Object {
"ROOT_QUERY": Object {
Expand Down
Loading