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: connect to a cloud session #4776

Merged
merged 3 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions docs/commands/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ netlify dev
- `live` (*boolean*) - start a public live session
- `offline` (*boolean*) - disables any features that require network access
- `port` (*string*) - port of netlify dev
- `sessionId` (*string*) - (Graph) connect to cloud session with ID [sessionId]
- `targetPort` (*string*) - port of target app server
- `debug` (*boolean*) - Print debugging information
- `httpProxy` (*string*) - Proxy server address to route requests through.
Expand Down
9 changes: 8 additions & 1 deletion src/commands/dev/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,13 @@ const dev = async (options, command) => {
graphqlDocument = defaultExampleOperationsDoc
}

stopWatchingCLISessions = await startOneGraphCLISession({ netlifyGraphConfig, netlifyToken, site, state })
stopWatchingCLISessions = await startOneGraphCLISession({
netlifyGraphConfig,
netlifyToken,
site,
state,
oneGraphSessionId: options.sessionId,
})

// Should be created by startOneGraphCLISession
const oneGraphSessionId = loadCLISession(state)
Expand Down Expand Up @@ -599,6 +605,7 @@ const createDevCommand = (program) => {
.hideHelp(),
)
.addOption(new Option('--graph', 'enable Netlify Graph support').hideHelp())
.addOption(new Option('--sessionId [sessionId]', '(Graph) connect to cloud session with ID [sessionId]'))
.addOption(
new Option(
'-e, --edgeInspect [address]',
Expand Down
11 changes: 7 additions & 4 deletions src/lib/one-graph/cli-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ const loadCLISession = (state) => state.get('oneGraphSessionId')
* Idemponentially save the CLI session id to the local state and start monitoring for CLI events, upstream schema changes, and local operation file changes
* @param {object} input
* @param {string} input.netlifyToken The (typically netlify) access token that is used for authentication, if any
* @param {string | undefined} input.oneGraphSessionId The session ID to use for this CLI session (default: read from state)
* @param {NetlifyGraph.NetlifyGraphConfig} input.netlifyGraphConfig A standalone config object that contains all the information necessary for Netlify Graph to process events
* @param {StateConfig} input.state A function to call to set/get the current state of the local Netlify project
* @param {any} input.site The site object
Expand All @@ -548,6 +549,7 @@ const startOneGraphCLISession = async (input) => {
netlifyToken,
site,
state,
oneGraphSessionId: input.oneGraphSessionId,
})

const enabledServices = []
Expand Down Expand Up @@ -657,8 +659,9 @@ const generateSessionName = () => {
/**
* Ensures a cli session exists for the current checkout, or errors out if it doesn't and cannot create one.
*/
const ensureCLISession = async ({ metadata, netlifyToken, site, state }) => {
let oneGraphSessionId = loadCLISession(state)
const ensureCLISession = async (input) => {
const { metadata, netlifyToken, site, state } = input
let oneGraphSessionId = input.oneGraphSessionId ? input.oneGraphSessionId : loadCLISession(state)
let parentCliSessionId = null

// Validate that session still exists and we can access it
Expand Down Expand Up @@ -697,14 +700,14 @@ const ensureCLISession = async ({ metadata, netlifyToken, site, state }) => {
sessionName,
metadata: sessionMetadata,
})
state.set('oneGraphSessionId', oneGraphSession.id)
oneGraphSessionId = state.get('oneGraphSessionId')
oneGraphSessionId = oneGraphSession.id
}

if (!oneGraphSessionId) {
error('Unable to create or access Netlify Graph CLI session')
}

state.set('oneGraphSessionId', oneGraphSessionId)
const { errors: markCLISessionActiveErrors } = await executeMarkCliSessionActiveHeartbeat(
netlifyToken,
site.id,
Expand Down