@strapi/plugin-graphql 4.0.5 → 4.1.0

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.0.5",
3
+ "version": "4.1.0",
4
4
  "description": "Adds GraphQL endpoint with default API methods.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,11 +30,11 @@
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.0.5",
33
+ "@strapi/utils": "4.1.0",
34
34
  "apollo-server-core": "3.1.2",
35
35
  "apollo-server-koa": "3.1.2",
36
36
  "glob": "^7.1.7",
37
- "graphql": "15.5.1",
37
+ "graphql": "^15.5.1",
38
38
  "graphql-depth-limit": "^1.1.0",
39
39
  "graphql-iso-date": "^3.6.1",
40
40
  "graphql-playground-middleware-koa": "^1.6.21",
@@ -43,7 +43,7 @@
43
43
  "graphql-upload": "^13.0.0",
44
44
  "koa-compose": "^4.1.0",
45
45
  "lodash": "4.17.21",
46
- "nexus": "1.1.0",
46
+ "nexus": "1.2.0",
47
47
  "pluralize": "^8.0.0",
48
48
  "subscriptions-transport-ws": "0.9.19"
49
49
  },
@@ -51,6 +51,9 @@
51
51
  "cross-env": "^7.0.3",
52
52
  "koa": "^2.13.1"
53
53
  },
54
+ "peerDependencies": {
55
+ "@strapi/strapi": "^4.0.0"
56
+ },
54
57
  "engines": {
55
58
  "node": ">=12.22.0 <=16.x.x",
56
59
  "npm": ">=6.0.0"
@@ -61,5 +64,5 @@
61
64
  "description": "Adds GraphQL endpoint with default API methods.",
62
65
  "kind": "plugin"
63
66
  },
64
- "gitHead": "45020eee065af8917011cc43398f95c4c624d6ad"
67
+ "gitHead": "d4273d81fbeec230b5734375e43a5f1f1f2a0231"
65
68
  }
@@ -1,10 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {
4
- mergeSchemas,
5
- makeExecutableSchema,
6
- addResolversToSchema,
7
- } = require('@graphql-tools/schema');
3
+ const { mergeSchemas, addResolversToSchema } = require('@graphql-tools/schema');
8
4
  const { pruneSchema } = require('@graphql-tools/utils');
9
5
  const { makeSchema } = require('nexus');
10
6
  const { prop, startsWith } = require('lodash/fp');
@@ -54,11 +50,8 @@ module.exports = ({ strapi }) => {
54
50
  shadowCRUD();
55
51
  }
56
52
 
57
- // Build a collection of schema based on the type registry (& temporary generated extension)
58
- const schemas = buildSchemas({ registry });
59
-
60
- // Merge every created schema into a single one
61
- const mergedSchema = mergeSchemas({ schemas });
53
+ // Build a merged schema from both Nexus types & SDL type definitions
54
+ const schema = buildMergedSchema({ registry });
62
55
 
63
56
  // Generate the extension configuration for the content API.
64
57
  // This extension instance needs to be generated after the Nexus schema's
@@ -67,42 +60,58 @@ module.exports = ({ strapi }) => {
67
60
  const extension = extensionService.generate({ typeRegistry: registry });
68
61
 
69
62
  // Add the extension's resolvers to the final schema
70
- const schema = addResolversToSchema(mergedSchema, extension.resolvers);
63
+ const schemaWithResolvers = addResolversToSchema(schema, extension.resolvers);
64
+
65
+ // Create a configuration object for the artifacts generation
66
+ const outputs = {
67
+ schema: config('artifacts.schema', false),
68
+ typegen: config('artifacts.typegen', false),
69
+ };
70
+
71
+ const currentEnv = strapi.config.get('environment');
72
+
73
+ const nexusSchema = makeSchema({
74
+ // Build the schema from the merged GraphQL schema.
75
+ // Since we're passing the schema to the mergeSchema property, it'll transform our SDL type definitions
76
+ // into Nexus type definition, thus allowing them to be handled by Nexus plugins & other processing
77
+ mergeSchema: { schema: schemaWithResolvers },
78
+
79
+ // Apply user-defined plugins
80
+ plugins: extension.plugins,
81
+
82
+ // Whether to generate artifacts (GraphQL schema, TS types definitions) or not.
83
+ // By default, we generate artifacts only on development environment
84
+ shouldGenerateArtifacts: config('generateArtifacts', currentEnv === 'development'),
85
+
86
+ // Artifacts generation configuration
87
+ outputs,
88
+ });
71
89
 
72
90
  // Wrap resolvers if needed (auth, middlewares, policies...) as configured in the extension
73
- const wrappedSchema = wrapResolvers({ schema, strapi, extension });
91
+ const wrappedNexusSchema = wrapResolvers({ schema: nexusSchema, strapi, extension });
74
92
 
75
93
  // Prune schema, remove unused types
76
94
  // eg: removes registered subscriptions if they're disabled in the config)
77
- const prunedSchema = pruneSchema(wrappedSchema);
95
+ const prunedNexusSchema = pruneSchema(wrappedNexusSchema);
78
96
 
79
- return prunedSchema;
97
+ return prunedNexusSchema;
80
98
  };
81
99
 
82
- const buildSchemas = ({ registry }) => {
100
+ const buildMergedSchema = ({ registry }) => {
83
101
  // Here we extract types, plugins & typeDefs from a temporary generated
84
102
  // extension since there won't be any addition allowed after schemas generation
85
- const { types, plugins, typeDefs = [] } = extensionService.generate({ typeRegistry: registry });
103
+ const { types, typeDefs = [] } = extensionService.generate({ typeRegistry: registry });
86
104
 
87
- // Create a new Nexus schema (shadow CRUD) & add it to the schemas collection
88
- const nexusSchema = makeSchema({
89
- types: [
90
- // Add the auto-generated Nexus types (shadow CRUD)
91
- registry.definitions,
92
- // Add every Nexus type registered using the extension service
93
- types,
94
- ],
95
-
96
- plugins: [
97
- // Add every plugin registered using the extension service
98
- ...plugins,
99
- ],
100
- });
101
-
102
- // Build schemas based on SDL type definitions (defined in the extension)
103
- const sdlSchemas = typeDefs.map(sdl => makeExecutableSchema({ typeDefs: sdl }));
105
+ // Nexus schema built with user-defined & shadow CRUD auto generated Nexus types
106
+ const nexusSchema = makeSchema({ types: [registry.definitions, types] });
104
107
 
105
- return [nexusSchema, ...sdlSchemas];
108
+ // Merge type definitions with the Nexus schema
109
+ return mergeSchemas({
110
+ typeDefs,
111
+ // Give access to the shadowCRUD & nexus based types
112
+ // Note: This is necessary so that types defined in SDL can reference types defined with Nexus
113
+ schemas: [nexusSchema],
114
+ });
106
115
  };
107
116
 
108
117
  const shadowCRUD = () => {