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

Core Data: Adds 'include' to the query key #34583

Merged
merged 1 commit into from
Sep 7, 2021
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
15 changes: 9 additions & 6 deletions packages/core-data/src/queried-data/get-query-parts.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ export function getQueryParts( query ) {
parts.perPage = Number( value );
break;

case 'include':
parts.include = getNormalizedCommaSeparable( value ).map(
Number
);
break;

case 'context':
parts.context = value;
break;
Expand All @@ -82,6 +76,15 @@ export function getQueryParts( query ) {
value = parts.fields.join();
}

// Two requests with different include values cannot have same results.
if ( key === 'include' ) {
parts.include = getNormalizedCommaSeparable( value ).map(
Number
);
// Normalize value for `stableKey`.
value = parts.include.join();
}

// While it could be any deterministic string, for simplicity's
// sake mimic querystring encoding for stable key.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe( 'getQueryParts', () => {
context: 'default',
page: 1,
perPage: 10,
stableKey: '',
stableKey: 'include=1',
fields: null,
include: [ 1 ],
} );
Expand Down
1 change: 1 addition & 0 deletions packages/core-data/src/queried-data/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe( 'getQueriedItems', () => {
queries: {
default: {
'': [ 1, 2 ],
'include=1': [ 1 ],
},
},
};
Expand Down