@strapi/plugin-graphql 4.2.0 → 4.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/plugin-graphql",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.3",
|
|
4
4
|
"description": "Adds GraphQL endpoint with default API methods.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@apollo/federation": "^0.28.0",
|
|
31
31
|
"@graphql-tools/schema": "8.1.2",
|
|
32
32
|
"@graphql-tools/utils": "^8.0.2",
|
|
33
|
-
"@strapi/utils": "4.2.
|
|
33
|
+
"@strapi/utils": "4.2.3",
|
|
34
34
|
"apollo-server-core": "3.1.2",
|
|
35
35
|
"apollo-server-koa": "3.1.2",
|
|
36
36
|
"glob": "^7.1.7",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"description": "Adds GraphQL endpoint with default API methods.",
|
|
65
65
|
"kind": "plugin"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "fe296baf71cb932d45183d5335285eaf30a6fad6"
|
|
68
68
|
}
|
|
@@ -14,7 +14,7 @@ module.exports = ({ strapi }) => {
|
|
|
14
14
|
const extension = strapi.plugin('graphql').service('extension');
|
|
15
15
|
|
|
16
16
|
const { getFiltersInputTypeName, getScalarFilterInputTypeName } = utils.naming;
|
|
17
|
-
const { isStrapiScalar, isRelation } = utils.attributes;
|
|
17
|
+
const { isStrapiScalar, isRelation, isComponent } = utils.attributes;
|
|
18
18
|
|
|
19
19
|
const { attributes } = contentType;
|
|
20
20
|
|
|
@@ -51,6 +51,11 @@ module.exports = ({ strapi }) => {
|
|
|
51
51
|
else if (isRelation(attribute)) {
|
|
52
52
|
addRelationalAttribute(t, attributeName, attribute);
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
// Handle components
|
|
56
|
+
else if (isComponent(attribute)) {
|
|
57
|
+
addComponentAttribute(t, attributeName, attribute);
|
|
58
|
+
}
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
// Conditional clauses
|
|
@@ -87,6 +92,22 @@ module.exports = ({ strapi }) => {
|
|
|
87
92
|
builder.field(attributeName, { type: getFiltersInputTypeName(model) });
|
|
88
93
|
};
|
|
89
94
|
|
|
95
|
+
const addComponentAttribute = (builder, attributeName, attribute) => {
|
|
96
|
+
const utils = strapi.plugin('graphql').service('utils');
|
|
97
|
+
const extension = strapi.plugin('graphql').service('extension');
|
|
98
|
+
const { getFiltersInputTypeName } = utils.naming;
|
|
99
|
+
|
|
100
|
+
const component = strapi.getModel(attribute.component);
|
|
101
|
+
|
|
102
|
+
// If there is no component corresponding to the attribute configuration, then ignore it
|
|
103
|
+
if (!component) return;
|
|
104
|
+
|
|
105
|
+
// If the component is disabled, then ignore it too
|
|
106
|
+
if (extension.shadowCRUD(component.uid).isDisabled()) return;
|
|
107
|
+
|
|
108
|
+
builder.field(attributeName, { type: getFiltersInputTypeName(component) });
|
|
109
|
+
};
|
|
110
|
+
|
|
90
111
|
return {
|
|
91
112
|
buildContentTypeFilters,
|
|
92
113
|
};
|
|
@@ -42,7 +42,7 @@ module.exports = ({ strapi }) => {
|
|
|
42
42
|
* @return {object | object[]}
|
|
43
43
|
*/
|
|
44
44
|
graphQLFiltersToStrapiQuery(filters, contentType = {}) {
|
|
45
|
-
const { isStrapiScalar, isMedia, isRelation } = getService('utils').attributes;
|
|
45
|
+
const { isStrapiScalar, isMedia, isRelation, isComponent } = getService('utils').attributes;
|
|
46
46
|
const { operators } = getService('builders').filters;
|
|
47
47
|
|
|
48
48
|
const ROOT_LEVEL_OPERATORS = [operators.and, operators.or, operators.not];
|
|
@@ -86,6 +86,16 @@ module.exports = ({ strapi }) => {
|
|
|
86
86
|
// and update the value within `resultMap`
|
|
87
87
|
resultMap[key] = this.graphQLFiltersToStrapiQuery(value, relModel);
|
|
88
88
|
}
|
|
89
|
+
|
|
90
|
+
// If it's a deep filter on a component
|
|
91
|
+
else if (isComponent(attribute)) {
|
|
92
|
+
// Fetch the model from the component attribute
|
|
93
|
+
const componentModel = strapi.getModel(attribute.component);
|
|
94
|
+
|
|
95
|
+
// Recursively apply the mapping to the value using the fetched model,
|
|
96
|
+
// and update the value within `resultMap`
|
|
97
|
+
resultMap[key] = this.graphQLFiltersToStrapiQuery(value, componentModel);
|
|
98
|
+
}
|
|
89
99
|
}
|
|
90
100
|
|
|
91
101
|
// Handle the case where the key is not an attribute (operator, ...)
|