Skip to content

Commit

Permalink
fix: Update graph edit (#4710)
Browse files Browse the repository at this point in the history
* fix: update graph-edit and make sure we ack cli events even if we fail on them

* chore: fix formatting

* fix: internal variable misnamed

* fix: executeCreatePersistedQuery

Co-authored-by: Antonio Nuno Monteiro <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 27, 2022
1 parent b00ad87 commit 85db12b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
28 changes: 21 additions & 7 deletions src/commands/graph/graph-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
const { NETLIFYDEVERR, chalk, error, log } = require('../../utils')
const { openBrowser } = require('../../utils/open-browser')

const { createPersistedQuery, ensureAppForSite } = OneGraphCliClient
const { ensureAppForSite, executeCreatePersistedQueryMutation } = OneGraphCliClient

/**
* Creates the `netlify graph:edit` command
Expand Down Expand Up @@ -50,12 +50,26 @@ const graphEdit = async (options, command) => {
})

const { branch } = gitRepoInfo()
const persistedDoc = await createPersistedQuery(netlifyToken, {
appId: siteId,
description: 'Temporary snapshot of local queries',
document: graphqlDocument,
tags: ['netlify-cli', `session:${oneGraphSessionId}`, `git-branch:${branch}`],
})
const persistedResult = await executeCreatePersistedQueryMutation(
{
nfToken: netlifyToken,
appId: siteId,
description: 'Temporary snapshot of local queries',
query: graphqlDocument,
tags: ['netlify-cli', `session:${oneGraphSessionId}`, `git-branch:${branch}`],
},
{
accessToken: netlifyToken,

siteId,
},
)

const persistedDoc =
persistedResult.data &&
persistedResult.data.oneGraph &&
persistedResult.data.oneGraph.createPersistedQuery &&
persistedResult.data.oneGraph.createPersistedQuery.persistedQuery

const newMetadata = { docId: persistedDoc.id }

Expand Down
4 changes: 2 additions & 2 deletions src/commands/graph/graph-operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ const graphOperations = async (options, command) => {
* @param {import('../base-command').BaseCommand} program
* @returns
*/
const createGraphOperationCommand = (program) =>
const createGraphOperationsCommand = (program) =>
program
.command('graph:operations')
.description('List all of the locally available operations')
.action(async (options, command) => {
await graphOperations(options, command)
})

module.exports = { createGraphOperationCommand }
module.exports = { createGraphOperationsCommand }
4 changes: 2 additions & 2 deletions src/commands/graph/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { createGraphConfigWriteCommand } = require('./graph-config-write')
const { createGraphEditCommand } = require('./graph-edit')
const { createGraphHandlerCommand } = require('./graph-handler')
const { createGraphLibraryCommand } = require('./graph-library')
const { createGraphOperationCommand } = require('./graph-operations')
const { createGraphOperationsCommand } = require('./graph-operations')
const { createGraphPullCommand } = require('./graph-pull')

/**
Expand All @@ -25,7 +25,7 @@ const createGraphCommand = (program) => {
createGraphEditCommand(program)
createGraphHandlerCommand(program)
createGraphLibraryCommand(program)
createGraphOperationCommand(program)
createGraphOperationsCommand(program)
createGraphPullCommand(program)

return program
Expand Down
44 changes: 34 additions & 10 deletions src/lib/one-graph/cli-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,14 @@ const monitorCLISessionEvents = (input) => {
const { events } = next

if (events.length !== 0) {
const ackIds = await onEvents(events)
await OneGraphClient.ackCLISessionEvents({ appId, authToken: netlifyToken, sessionId, eventIds: ackIds })
let ackIds = []
try {
ackIds = await onEvents(events)
} catch (eventHandlerError) {
warn(`Error handling event: ${eventHandlerError}`)
} finally {
await OneGraphClient.ackCLISessionEvents({ appId, authToken: netlifyToken, sessionId, eventIds: ackIds })
}
}

await enabledServiceWatcher(netlifyToken, appId)
Expand Down Expand Up @@ -474,14 +480,31 @@ const persistNewOperationsDocForSession = async ({
siteRoot,
}) => {
const { branch } = gitRepoInfo()
const payload = {
appId: siteId,
description: 'Temporary snapshot of local queries',
document: operationsDoc,
tags: ['netlify-cli', `session:${oneGraphSessionId}`, `git-branch:${branch}`, `local-change`],
const persistedResult = await executeCreatePersistedQueryMutation(
{
nfToken: netlifyToken,
appId: siteId,
description: 'Temporary snapshot of local queries',
query: operationsDoc,
tags: ['netlify-cli', `session:${oneGraphSessionId}`, `git-branch:${branch}`, `local-change`],
},
{
accessToken: netlifyToken,
siteId,
},
)

const persistedDoc =
persistedResult.data &&
persistedResult.data.oneGraph &&
persistedResult.data.oneGraph.createPersistedQuery &&
persistedResult.data.oneGraph.createPersistedQuery.persistedQuery

if (!persistedDoc) {
warn(`Failed to create persisted query for editing, ${JSON.stringify(persistedResult, null, 2)}`)
}
const persistedDoc = await executeCreatePersistedQueryMutation(netlifyToken, payload)
const newMetadata = await { docId: persistedDoc.id }

const newMetadata = { docId: persistedDoc.id }
const result = await upsertMergeCLISessionMetadata({
netlifyGraphConfig,
netlifyToken,
Expand Down Expand Up @@ -697,7 +720,8 @@ const ensureCLISession = async ({ metadata, netlifyToken, site, state }) => {

const OneGraphCliClient = {
ackCLISessionEvents: OneGraphClient.ackCLISessionEvents,
createPersistedQuery: executeCreatePersistedQueryMutation,
executeCreatePersistedQueryMutation: OneGraphClient.executeCreatePersistedQueryMutation,
executeCreateApiTokenMutation: OneGraphClient.executeCreateApiTokenMutation,
fetchCliSessionEvents: OneGraphClient.fetchCliSessionEvents,
ensureAppForSite,
updateCLISessionMetadata,
Expand Down

1 comment on commit 85db12b

@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: 221 MB

Please sign in to comment.