netlify-cli 9.0.5 → 9.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/README.md CHANGED
@@ -159,6 +159,7 @@ Manage netlify functions
159
159
 
160
160
  | Subcommand | description |
161
161
  |:--------------------------- |:-----|
162
+ | [`graph:config:write`](/docs/commands/graph.md#graphconfigwrite) | Write a .graphqlrc.json file to the current directory for use with local tooling (e.g. the graphql extension for vscode) |
162
163
  | [`graph:edit`](/docs/commands/graph.md#graphedit) | Launch the browser to edit your local graph functions from Netlify |
163
164
  | [`graph:handler`](/docs/commands/graph.md#graphhandler) | Generate a handler for a Graph operation given its name. See `graph:operations` for a list of operations. |
164
165
  | [`graph:library`](/docs/commands/graph.md#graphlibrary) | Generate the Graph function library |
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "netlify-cli",
3
- "version": "9.0.5",
3
+ "version": "9.1.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "netlify-cli",
9
- "version": "9.0.5",
9
+ "version": "9.1.0",
10
10
  "hasInstallScript": true,
11
11
  "license": "MIT",
12
12
  "dependencies": {
@@ -82,7 +82,7 @@
82
82
  "multiparty": "^4.2.1",
83
83
  "netlify": "^11.0.0",
84
84
  "netlify-headers-parser": "^6.0.1",
85
- "netlify-onegraph-internal": "0.0.32",
85
+ "netlify-onegraph-internal": "0.0.37",
86
86
  "netlify-redirect-parser": "^13.0.2",
87
87
  "netlify-redirector": "^0.2.1",
88
88
  "node-fetch": "^2.6.0",
@@ -16558,9 +16558,9 @@
16558
16558
  }
16559
16559
  },
16560
16560
  "node_modules/netlify-onegraph-internal": {
16561
- "version": "0.0.32",
16562
- "resolved": "https://registry.npmjs.org/netlify-onegraph-internal/-/netlify-onegraph-internal-0.0.32.tgz",
16563
- "integrity": "sha512-coV53I8OWqsv6pF5+e7nnIh9wbFcitkdbptsRyhuToJvzbJPvf9F0Ym47bsO6kfnj2iXDZEnT44O5i0gaBmcMQ==",
16561
+ "version": "0.0.37",
16562
+ "resolved": "https://registry.npmjs.org/netlify-onegraph-internal/-/netlify-onegraph-internal-0.0.37.tgz",
16563
+ "integrity": "sha512-EjcLO4jafn2mKVval6hns7wdqT28c7rHJyOzYTUa5ViU+L4eF6CweA4jjH36rmsFxNJchQBpzR2zl/KY4auOKg==",
16564
16564
  "dependencies": {
16565
16565
  "graphql": "16.0.0",
16566
16566
  "node-fetch": "^2.6.0",
@@ -35961,9 +35961,9 @@
35961
35961
  }
35962
35962
  },
35963
35963
  "netlify-onegraph-internal": {
35964
- "version": "0.0.32",
35965
- "resolved": "https://registry.npmjs.org/netlify-onegraph-internal/-/netlify-onegraph-internal-0.0.32.tgz",
35966
- "integrity": "sha512-coV53I8OWqsv6pF5+e7nnIh9wbFcitkdbptsRyhuToJvzbJPvf9F0Ym47bsO6kfnj2iXDZEnT44O5i0gaBmcMQ==",
35964
+ "version": "0.0.37",
35965
+ "resolved": "https://registry.npmjs.org/netlify-onegraph-internal/-/netlify-onegraph-internal-0.0.37.tgz",
35966
+ "integrity": "sha512-EjcLO4jafn2mKVval6hns7wdqT28c7rHJyOzYTUa5ViU+L4eF6CweA4jjH36rmsFxNJchQBpzR2zl/KY4auOKg==",
35967
35967
  "requires": {
35968
35968
  "graphql": "16.0.0",
35969
35969
  "node-fetch": "^2.6.0",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "netlify-cli",
3
3
  "description": "Netlify command line tool",
4
- "version": "9.0.5",
4
+ "version": "9.1.0",
5
5
  "author": "Netlify Inc.",
6
6
  "contributors": [
7
7
  "Abraham Schilling <AbrahamSchilling@gmail.com> (https://gitlab.com/n4bb12)",
@@ -164,6 +164,7 @@
164
164
  "url": "https://github.com/netlify/cli/issues"
165
165
  },
166
166
  "scripts": {
167
+ "snap": "ava --verbose -u tests/integration/**/*graph*.test.js",
167
168
  "prepare": "husky install node_modules/@netlify/eslint-config-node/.husky/",
168
169
  "start": "node ./bin/run",
169
170
  "test": "run-s format test:dev",
@@ -270,7 +271,7 @@
270
271
  "multiparty": "^4.2.1",
271
272
  "netlify": "^11.0.0",
272
273
  "netlify-headers-parser": "^6.0.1",
273
- "netlify-onegraph-internal": "0.0.32",
274
+ "netlify-onegraph-internal": "0.0.37",
274
275
  "netlify-redirect-parser": "^13.0.2",
275
276
  "netlify-redirector": "^0.2.1",
276
277
  "node-fetch": "^2.6.0",
@@ -0,0 +1,55 @@
1
+ // @ts-check
2
+ const fs = require('fs')
3
+ const path = require('path')
4
+
5
+ const { getNetlifyGraphConfig } = require('../../lib/one-graph/cli-netlify-graph')
6
+ const { NETLIFYDEVERR, chalk, error } = require('../../utils')
7
+
8
+ /**
9
+ * Creates the `netlify graph:config:write` command
10
+ * @param {import('commander').OptionValues} options
11
+ * @param {import('../base-command').BaseCommand} command
12
+ * @returns
13
+ */
14
+ const graphConfigWrite = async (options, command) => {
15
+ const { site } = command.netlify
16
+
17
+ if (!site.id) {
18
+ error(
19
+ `${NETLIFYDEVERR} Warning: no siteId defined, unable to start Netlify Graph. To enable, run ${chalk.yellow(
20
+ 'netlify init',
21
+ )} or ${chalk.yellow('netlify link')}`,
22
+ )
23
+ }
24
+
25
+ const netlifyGraphConfig = await getNetlifyGraphConfig({ command, options })
26
+
27
+ const schemaPath = netlifyGraphConfig.graphQLSchemaFilename.join('/')
28
+
29
+ // Support tools that looks for the schema under different keys
30
+ const graphQLConfig = {
31
+ schema: [schemaPath],
32
+ schemaPath: [schemaPath],
33
+ }
34
+
35
+ const filePath = path.resolve(...netlifyGraphConfig.graphQLConfigJsonFilename)
36
+
37
+ fs.writeFileSync(filePath, JSON.stringify(graphQLConfig, null, 2))
38
+ }
39
+
40
+ /**
41
+ * Creates the `netlify graph:config:write` command
42
+ * @param {import('../base-command').BaseCommand} program
43
+ * @returns
44
+ */
45
+ const createGraphConfigWriteCommand = (program) =>
46
+ program
47
+ .command('graph:config:write')
48
+ .description(
49
+ 'Write a .graphqlrc.json file to the current directory for use with local tooling (e.g. the graphql extension for vscode)',
50
+ )
51
+ .action(async (options, command) => {
52
+ await graphConfigWrite(options, command)
53
+ })
54
+
55
+ module.exports = { createGraphConfigWriteCommand }
@@ -1,4 +1,5 @@
1
1
  // @ts-check
2
+ const { createGraphConfigWriteCommand } = require('./graph-config-write')
2
3
  const { createGraphEditCommand } = require('./graph-edit')
3
4
  const { createGraphHandlerCommand } = require('./graph-handler')
4
5
  const { createGraphLibraryCommand } = require('./graph-library')
@@ -20,6 +21,7 @@ const graph = (options, command) => {
20
21
  * @returns
21
22
  */
22
23
  const createGraphCommand = (program) => {
24
+ createGraphConfigWriteCommand(program)
23
25
  createGraphEditCommand(program)
24
26
  createGraphHandlerCommand(program)
25
27
  createGraphLibraryCommand(program)
@@ -16,6 +16,7 @@ const { watchDebounced } = require('../functions/watcher')
16
16
  const {
17
17
  generateFunctionsFile,
18
18
  generateHandlerByOperationId,
19
+ normalizeOperationsDoc,
19
20
  readGraphQLOperationsSourceFile,
20
21
  writeGraphQLOperationsSourceFile,
21
22
  writeGraphQLSchemaFile,
@@ -231,7 +232,8 @@ const updateGraphQLOperationsFileFromPersistedDoc = async (input) => {
231
232
  return
232
233
  }
233
234
 
234
- const doc = persistedDoc.query
235
+ // Sorts the operations stably, prepends the @netlify directive, etc.
236
+ const doc = normalizeOperationsDoc(persistedDoc.query)
235
237
 
236
238
  writeGraphQLOperationsSourceFile(netlifyGraphConfig, doc)
237
239
  regenerateFunctionsFileFromOperationsFile({ netlifyGraphConfig, schema })
@@ -3,7 +3,7 @@ const fs = require('fs')
3
3
  const path = require('path')
4
4
  const process = require('process')
5
5
 
6
- const { GraphQL, InternalConsole, NetlifyGraph } = require('netlify-onegraph-internal')
6
+ const { GraphQL, GraphQLHelpers, InternalConsole, NetlifyGraph } = require('netlify-onegraph-internal')
7
7
 
8
8
  const { detectServerSettings, error, execa, getFunctionsDir, log, warn } = require('../../utils')
9
9
 
@@ -202,6 +202,10 @@ const getNetlifyGraphConfig = async ({ command, options, settings }) => {
202
202
  (userSpecifiedConfig.graphQLOperationsSourceFilename &&
203
203
  userSpecifiedConfig.graphQLOperationsSourceFilename.split(path.sep)) ||
204
204
  defaultFrameworkConfig.graphQLOperationsSourceFilename
205
+ const graphQLConfigJsonFilename =
206
+ (userSpecifiedConfig.graphQLConfigJsonFilename && userSpecifiedConfig.graphQLConfigJsonFilename.split(path.sep)) ||
207
+ defaultFrameworkConfig.graphQLConfigJsonFilename ||
208
+ baseConfig.graphQLConfigJsonFilename
205
209
  const graphQLSchemaFilename =
206
210
  (userSpecifiedConfig.graphQLSchemaFilename && userSpecifiedConfig.graphQLSchemaFilename.split(path.sep)) ||
207
211
  defaultFrameworkConfig.graphQLSchemaFilename
@@ -229,6 +233,7 @@ const getNetlifyGraphConfig = async ({ command, options, settings }) => {
229
233
  netlifyGraphTypeDefinitionsFilename,
230
234
  graphQLOperationsSourceFilename,
231
235
  graphQLSchemaFilename,
236
+ graphQLConfigJsonFilename,
232
237
  netlifyGraphRequirePath,
233
238
  framework,
234
239
  language,
@@ -505,6 +510,7 @@ module.exports = {
505
510
  getGraphEditUrlBySiteId,
506
511
  getGraphEditUrlBySiteName,
507
512
  getNetlifyGraphConfig,
513
+ normalizeOperationsDoc: GraphQLHelpers.normalizeOperationsDoc,
508
514
  parse,
509
515
  readGraphQLOperationsSourceFile,
510
516
  readGraphQLSchemaFile,