File tree 3 files changed +30
-7
lines changed
3 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ import {
36
36
} from './utils/validate-params'
37
37
import validateSearchParameters from './utils/validate-search-parameters'
38
38
import validateTimestamp from './utils/validate-timestamp'
39
+ import getQuerySelectionSet from './utils/query-selection-set'
39
40
40
41
const ASSET_KEY_MAX_LIFETIME = 48 * 60 * 60
41
42
@@ -107,6 +108,18 @@ export default function createContentfulApi<OptionType extends ChainOptions>(
107
108
108
109
if ( areAllowed ) {
109
110
query . includeContentSourceMaps = true
111
+
112
+ // Ensure that content source maps related attributes are selected
113
+ if ( query . select ) {
114
+ const selection = getQuerySelectionSet ( query )
115
+
116
+ if ( ! selection . has ( 'sys' ) ) {
117
+ selection . add ( 'sys.contentSourceMaps' )
118
+ selection . add ( 'sys.contentSourceMapsLookup' )
119
+ }
120
+
121
+ query . select = [ ...selection ] . join ( ',' )
122
+ }
110
123
}
111
124
112
125
return query
Original file line number Diff line number Diff line change
1
+ import getQuerySelectionSet from './query-selection-set'
2
+
1
3
/*
2
4
* sdk relies heavily on sys metadata
3
5
* so we cannot omit the sys property on sdk level entirely
@@ -9,13 +11,7 @@ export default function normalizeSelect(query) {
9
11
return query
10
12
}
11
13
12
- // The selection of fields for the query is limited
13
- // Get the different parts that are listed for selection
14
- const allSelects = Array . isArray ( query . select )
15
- ? query . select
16
- : query . select . split ( ',' ) . map ( ( q ) => q . trim ( ) )
17
- // Move the parts into a set for easy access and deduplication
18
- const selectedSet = new Set ( allSelects )
14
+ const selectedSet = getQuerySelectionSet ( query )
19
15
20
16
// If we already select all of `sys` we can just return
21
17
// since we're anyway fetching everything that is needed
Original file line number Diff line number Diff line change
1
+ export default function getQuerySelectionSet ( query : Record < string , any > ) : Set < string > {
2
+ if ( ! query . select ) {
3
+ return new Set ( )
4
+ }
5
+
6
+ // The selection of fields for the query is limited
7
+ // Get the different parts that are listed for selection
8
+ const allSelects = Array . isArray ( query . select )
9
+ ? query . select
10
+ : query . select . split ( ',' ) . map ( ( q ) => q . trim ( ) )
11
+
12
+ // Move the parts into a set for easy access and deduplication
13
+ return new Set ( allSelects )
14
+ }
You can’t perform that action at this time.
0 commit comments