@strapi/plugin-graphql 4.3.0-beta.1 → 4.3.1

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.
@@ -0,0 +1,4 @@
1
+ {
2
+ "plugin.description.long": "Dodaje GraphQL endpoint z domyślnymi metodami API.",
3
+ "plugin.description.short": "Dodaje GraphQL endpoint z domyślnymi metodami API."
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/plugin-graphql",
3
- "version": "4.3.0-beta.1",
3
+ "version": "4.3.1",
4
4
  "description": "Adds GraphQL endpoint with default API methods.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,9 +30,9 @@
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.3.0-beta.1",
33
+ "@strapi/utils": "4.3.1",
34
34
  "apollo-server-core": "3.1.2",
35
- "apollo-server-koa": "3.1.2",
35
+ "apollo-server-koa": "3.10.0",
36
36
  "glob": "^7.1.7",
37
37
  "graphql": "^15.5.1",
38
38
  "graphql-depth-limit": "^1.1.0",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "cross-env": "^7.0.3",
52
- "koa": "^2.13.1"
52
+ "koa": "^2.13.4"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@strapi/strapi": "^4.0.0"
@@ -64,5 +64,5 @@
64
64
  "description": "Adds GraphQL endpoint with default API methods.",
65
65
  "kind": "plugin"
66
66
  },
67
- "gitHead": "9d6555398960c39159d66bb4eea3bcb0362e37e3"
67
+ "gitHead": "1eab2fb08c7a4d3d40a5a7ff3b2f137ce0afcf8a"
68
68
  }
@@ -110,6 +110,9 @@ module.exports = async ({ strapi }) => {
110
110
  },
111
111
  };
112
112
 
113
+ // allow graphql playground to load without authentication
114
+ if (ctx.request.method === 'GET') return next();
115
+
113
116
  return strapi.auth.authenticate(ctx, next);
114
117
  },
115
118
 
@@ -3,7 +3,7 @@
3
3
  const { Kind, valueFromASTUntyped } = require('graphql');
4
4
  const { omit } = require('lodash/fp');
5
5
  const { unionType, scalarType } = require('nexus');
6
- const { ApplicationError } = require('@strapi/utils');
6
+ const { ApplicationError } = require('@strapi/utils').errors;
7
7
 
8
8
  module.exports = ({ strapi }) => {
9
9
  const buildTypeDefinition = (name, components) => {
@@ -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
  };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const EQI_FIELD_NAME = 'eqi';
4
+
5
+ module.exports = () => ({
6
+ fieldName: EQI_FIELD_NAME,
7
+
8
+ strapiOperator: '$eqi',
9
+
10
+ add(t, type) {
11
+ t.field(EQI_FIELD_NAME, { type });
12
+ },
13
+ });
@@ -8,6 +8,7 @@ const operators = {
8
8
  not: require('./not'),
9
9
 
10
10
  eq: require('./eq'),
11
+ eqi: require('./eqi'),
11
12
  ne: require('./ne'),
12
13
 
13
14
  startsWith: require('./starts-with'),
@@ -85,6 +85,7 @@ const allOperators = [
85
85
  'not',
86
86
 
87
87
  'eq',
88
+ 'eqi',
88
89
  'ne',
89
90
 
90
91
  'startsWith',
@@ -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, ...)