-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Graph config netlify directive (#4239)
- Loading branch information
Showing
15 changed files
with
35,485 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// @ts-check | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const { getNetlifyGraphConfig } = require('../../lib/one-graph/cli-netlify-graph') | ||
const { NETLIFYDEVERR, chalk, error } = require('../../utils') | ||
|
||
/** | ||
* Creates the `netlify graph:config:write` command | ||
* @param {import('commander').OptionValues} options | ||
* @param {import('../base-command').BaseCommand} command | ||
* @returns | ||
*/ | ||
const graphConfigWrite = async (options, command) => { | ||
const { site } = command.netlify | ||
|
||
if (!site.id) { | ||
error( | ||
`${NETLIFYDEVERR} Warning: no siteId defined, unable to start Netlify Graph. To enable, run ${chalk.yellow( | ||
'netlify init', | ||
)} or ${chalk.yellow('netlify link')}`, | ||
) | ||
} | ||
|
||
const netlifyGraphConfig = await getNetlifyGraphConfig({ command, options }) | ||
|
||
const schemaPath = netlifyGraphConfig.graphQLSchemaFilename.join('/') | ||
|
||
// Support tools that looks for the schema under different keys | ||
const graphQLConfig = { | ||
schema: [schemaPath], | ||
schemaPath: [schemaPath], | ||
} | ||
|
||
const filePath = path.resolve(...netlifyGraphConfig.graphQLConfigJsonFilename) | ||
|
||
fs.writeFileSync(filePath, JSON.stringify(graphQLConfig, null, 2)) | ||
} | ||
|
||
/** | ||
* Creates the `netlify graph:config:write` command | ||
* @param {import('../base-command').BaseCommand} program | ||
* @returns | ||
*/ | ||
const createGraphConfigWriteCommand = (program) => | ||
program | ||
.command('graph:config:write') | ||
.description( | ||
'Write a .graphqlrc.json file to the current directory for use with local tooling (e.g. the graphql extension for vscode)', | ||
) | ||
.action(async (options, command) => { | ||
await graphConfigWrite(options, command) | ||
}) | ||
|
||
module.exports = { createGraphConfigWriteCommand } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
cbee71c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📊 Benchmark results
Package size: 508 MB