Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(graph): allow sharing VCS branches through a lockfile #4899

Merged
merged 7 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Manage netlify functions
| [`graph:init`](/docs/commands/graph.md#graphinit) | Initialize all the resources for Netlify Graph |
| [`graph:library`](/docs/commands/graph.md#graphlibrary) | Generate the Graph function library |
| [`graph:operations`](/docs/commands/graph.md#graphoperations) | List all of the locally available operations |
| [`graph:pull`](/docs/commands/graph.md#graphpull) | Pull down your local Netlify Graph schema, and process pending Graph edit events |
| [`graph:pull`](/docs/commands/graph.md#graphpull) | Pull your remote Netlify Graph schema locally, and process pending Graph edit events |


### [init](/docs/commands/init.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Manage netlify functions
| [`graph:init`](/docs/commands/graph.md#graphinit) | Initialize all the resources for Netlify Graph |
| [`graph:library`](/docs/commands/graph.md#graphlibrary) | Generate the Graph function library |
| [`graph:operations`](/docs/commands/graph.md#graphoperations) | List all of the locally available operations |
| [`graph:pull`](/docs/commands/graph.md#graphpull) | Pull down your local Netlify Graph schema, and process pending Graph edit events |
| [`graph:pull`](/docs/commands/graph.md#graphpull) | Pull your remote Netlify Graph schema locally, and process pending Graph edit events |


### [init](/docs/commands/init.md)
Expand Down
4 changes: 2 additions & 2 deletions docs/commands/graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ netlify graph
| [`graph:init`](/docs/commands/graph.md#graphinit) | Initialize all the resources for Netlify Graph |
| [`graph:library`](/docs/commands/graph.md#graphlibrary) | Generate the Graph function library |
| [`graph:operations`](/docs/commands/graph.md#graphoperations) | List all of the locally available operations |
| [`graph:pull`](/docs/commands/graph.md#graphpull) | Pull down your local Netlify Graph schema, and process pending Graph edit events |
| [`graph:pull`](/docs/commands/graph.md#graphpull) | Pull your remote Netlify Graph schema locally, and process pending Graph edit events |


**Examples**
Expand Down Expand Up @@ -147,7 +147,7 @@ netlify graph:operations
---
## `graph:pull`

Pull down your local Netlify Graph schema, and process pending Graph edit events
Pull your remote Netlify Graph schema locally, and process pending Graph edit events

**Usage**

Expand Down
2 changes: 1 addition & 1 deletion docs/commands/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Manage netlify functions
| [`graph:init`](/docs/commands/graph.md#graphinit) | Initialize all the resources for Netlify Graph |
| [`graph:library`](/docs/commands/graph.md#graphlibrary) | Generate the Graph function library |
| [`graph:operations`](/docs/commands/graph.md#graphoperations) | List all of the locally available operations |
| [`graph:pull`](/docs/commands/graph.md#graphpull) | Pull down your local Netlify Graph schema, and process pending Graph edit events |
| [`graph:pull`](/docs/commands/graph.md#graphpull) | Pull your remote Netlify Graph schema locally, and process pending Graph edit events |


### [init](/docs/commands/init.md)
Expand Down
26 changes: 19 additions & 7 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
"multiparty": "^4.2.1",
"netlify": "^12.0.0",
"netlify-headers-parser": "^6.0.2",
"netlify-onegraph-internal": "0.4.1",
"netlify-onegraph-internal": "0.4.2",
"netlify-redirect-parser": "^13.0.5",
"netlify-redirector": "^0.2.1",
"node-fetch": "^2.6.0",
Expand Down
1 change: 1 addition & 0 deletions src/commands/graph/graph-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const graphEdit = async (options, command) => {
netlifyToken,
site,
state,
netlifyGraphConfig,
})

const { branch } = gitRepoInfo()
Expand Down
3 changes: 3 additions & 0 deletions src/commands/graph/graph-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { OneGraphClient } = require('netlify-onegraph-internal')
const { v4: uuidv4 } = require('uuid')

const { OneGraphCliClient, ensureCLISession } = require('../../lib/one-graph/cli-client')
const { getNetlifyGraphConfig } = require('../../lib/one-graph/cli-netlify-graph')
const { NETLIFYDEVERR, chalk, error, exit, getToken, log } = require('../../utils')
const { msg } = require('../login/login')

Expand Down Expand Up @@ -63,11 +64,13 @@ const graphInit = async (options, command) => {

await ensureAppForSite(netlifyToken, siteId)

const netlifyGraphConfig = await getNetlifyGraphConfig({ command, options })
await ensureCLISession({
metadata: {},
netlifyToken,
site,
state,
netlifyGraphConfig,
})

let envChanged = false
Expand Down
16 changes: 15 additions & 1 deletion src/commands/graph/graph-library.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
const { readLockfile } = require('../../lib/one-graph/cli-client')
const {
buildSchema,
defaultExampleOperationsDoc,
Expand All @@ -9,7 +10,7 @@ const {
readGraphQLOperationsSourceFile,
readGraphQLSchemaFile,
} = require('../../lib/one-graph/cli-netlify-graph')
const { error, log } = require('../../utils')
const { NETLIFYDEVERR, chalk, error, log } = require('../../utils')

/**
* Creates the `netlify graph:library` command
Expand Down Expand Up @@ -42,10 +43,23 @@ const graphLibrary = async (options, command) => {
const parsedDoc = parse(currentOperationsDoc)
const { fragments, functions } = extractFunctionsFromOperationDoc(parsedDoc)

const lockfile = readLockfile({ siteRoot: command.netlify.site.root })

if (lockfile == null) {
error(
`${NETLIFYDEVERR} Error: no lockfile found, unable to run \`netlify graph:library\`. To pull a remote schema (and create a lockfile), run ${chalk.yellow(
'netlify graph:pull',
)} `,
)
}

const schemaId = lockfile && lockfile.locked.schemaId

generateFunctionsFile({
logger: log,
netlifyGraphConfig,
schema,
schemaId,
operationsDoc: currentOperationsDoc,
functions,
fragments,
Expand Down
16 changes: 8 additions & 8 deletions src/commands/graph/graph-pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ const graphPull = async (options, command) => {
const { jwt } = await OneGraphCliClient.getGraphJwtForSite({ siteId, nfToken: netlifyToken })

const oneGraphSessionId = loadCLISession(state)
if (!oneGraphSessionId) {
warn(
'No local Netlify Graph session found, skipping command queue drain. Create a new session by running `netlify graph:edit`.',
)
return
}

await refetchAndGenerateFromOneGraph({
logger: log,
netlifyGraphConfig,
Expand All @@ -43,13 +50,6 @@ const graphPull = async (options, command) => {
sessionId: oneGraphSessionId,
})

if (!oneGraphSessionId) {
warn(
'No local Netlify Graph session found, skipping command queue drain. Create a new session by running `netlify graph:edit`.',
)
return
}

const schemaString = readGraphQLSchemaFile(netlifyGraphConfig)

let schema
Expand Down Expand Up @@ -106,7 +106,7 @@ const graphPull = async (options, command) => {
const createGraphPullCommand = (program) =>
program
.command('graph:pull')
.description('Pull down your local Netlify Graph schema, and process pending Graph edit events')
.description('Pull your remote Netlify Graph schema locally, and process pending Graph edit events')
.action(async (options, command) => {
await graphPull(options, command)
})
Expand Down
Loading