Skip to content

Commit

Permalink
feat(graph): allow sharing VCS branches through a lockfile (#4899)
Browse files Browse the repository at this point in the history
* feat(graph): allow sharing VCS branches through a lockfile

* fix: sean's review comments

* fix: generate docs

* fix(graph:pull): make sure there's a session before fetching schema

* fix(tests): update graph snapshots

* fix(deps): upgrade onegraph-internal with lockfile support

* fix: remove wrong optimization
  • Loading branch information
anmonteiro committed Aug 4, 2022
1 parent b3dc897 commit ad84a46
Show file tree
Hide file tree
Showing 13 changed files with 232 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
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
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
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
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
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
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
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
@@ -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
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

1 comment on commit ad84a46

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 230 MB

Please sign in to comment.