Skip to content

Commit

Permalink
fix(graph): don't attach codegen to session metadata, and don't die w…
Browse files Browse the repository at this point in the history
…hen missing toml config (#4951)

* fix: don't pass codegen as session metadata and warn on failed session update

* fix: unnecessary eslint rules
  • Loading branch information
sgrove authored Aug 15, 2022
1 parent 75d581f commit e9fa5e3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 38 deletions.
14 changes: 7 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 @@ -293,7 +293,7 @@
"multiparty": "^4.2.1",
"netlify": "^12.0.0",
"netlify-headers-parser": "^6.0.2",
"netlify-onegraph-internal": "0.8.6",
"netlify-onegraph-internal": "0.8.7",
"netlify-redirect-parser": "^13.0.5",
"netlify-redirector": "^0.2.1",
"node-fetch": "^2.6.0",
Expand Down
42 changes: 13 additions & 29 deletions src/lib/one-graph/cli-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,10 +780,9 @@ const getCLISessionMetadata = async ({ jwt, oneGraphSessionId, siteId }) => {
* Look at the current project, filesystem, etc. and determine relevant metadata for a cli session
* @param {object} input
* @param {string} input.siteRoot The root file path for the site
* @param {object} input.config The parsed netlify.toml config file
* @returns {Promise<CliEventHelper.DetectedLocalCLISessionMetadata>} Any locally detected facts that are relevant to include in the cli session metadata
*/
const detectLocalCLISessionMetadata = async ({ config, siteRoot }) => {
const detectLocalCLISessionMetadata = async ({ siteRoot }) => {
// @ts-ignore
const { listFrameworks } = await frameworkInfoPromise

Expand All @@ -806,25 +805,6 @@ const detectLocalCLISessionMetadata = async ({ config, siteRoot }) => {

const editor = process.env.EDITOR || null

/** @type {CodegenHelpers.CodegenModuleMeta | null} */
let codegen = null

const codegenModule = await getCodegenModule({ config })

if (codegenModule) {
codegen = {
id: codegenModule.id,
version: codegenModule.id,
generators: codegenModule.generators.map((generator) => ({
id: generator.id,
name: generator.name,
options: generator.generateHandlerOptions || null,
supportedDefinitionTypes: generator.supportedDefinitionTypes,
version: generator.version,
})),
}
}

const detectedMetadata = {
gitBranch: branch,
hostname,
Expand All @@ -835,8 +815,8 @@ const detectLocalCLISessionMetadata = async ({ config, siteRoot }) => {
platform,
arch,
nodeVersion: process.version,
codegen,
framework,
codegen: null,
}

return detectedMetadata
Expand All @@ -847,13 +827,12 @@ const detectLocalCLISessionMetadata = async ({ config, siteRoot }) => {
* @param {object} input
* @param {string} input.jwt The GraphJWT string
* @param {string} input.sessionId The id of the cli session to fetch the current metadata for
* @param {object} input.config The parsed netlify.toml config file
* @param {string} input.siteRoot Path to the root of the project
* @param {string} input.docId The GraphQL operations document id to fetch
* @param {string} input.schemaId The GraphQL schemaId to use when generating code
*/
const publishCliSessionMetadataPublishEvent = async ({ config, docId, jwt, schemaId, sessionId, siteRoot }) => {
const detectedMetadata = await detectLocalCLISessionMetadata({ config, siteRoot })
const publishCliSessionMetadataPublishEvent = async ({ docId, jwt, schemaId, sessionId, siteRoot }) => {
const detectedMetadata = await detectLocalCLISessionMetadata({ siteRoot })

/** @type {CliEventHelper.OneGraphNetlifyCliSessionMetadataPublishEvent} */
const event = {
Expand Down Expand Up @@ -901,13 +880,13 @@ const publishCliSessionMetadataPublishEvent = async ({ config, docId, jwt, schem
* @param {object} input.newMetadata The metadata to merge into (with priority) the existing metadata
* @returns {Promise<object>}
*/
const upsertMergeCLISessionMetadata = async ({ config, jwt, newMetadata, oneGraphSessionId, siteId, siteRoot }) => {
const upsertMergeCLISessionMetadata = async ({ jwt, newMetadata, oneGraphSessionId, siteId, siteRoot }) => {
const { errors, metadata } = await getCLISessionMetadata({ jwt, oneGraphSessionId, siteId })
if (errors) {
warn(`Error fetching cli session metadata: ${JSON.stringify(errors, null, 2)}`)
}

const detectedMetadata = await detectLocalCLISessionMetadata({ config, siteRoot })
const detectedMetadata = await detectLocalCLISessionMetadata({ siteRoot })

// @ts-ignore
const finalMetadata = { ...metadata, ...detectedMetadata, ...newMetadata }
Expand Down Expand Up @@ -992,7 +971,13 @@ const persistNewOperationsDocForSession = async ({
})

if (!result || result.errors) {
warn(`Unable to update session metadata with updated operations doc ${JSON.stringify(result.errors, null, 2)}`)
warn(
`Unable to update session metadata with updated operations docId="${persistedDoc.id}": ${JSON.stringify(
result && result.errors,
null,
2,
)}`,
)
} else if (lockfile != null) {
// Now that we've persisted the document, lock it in the lockfile
const currentOperationsDoc = readGraphQLOperationsSourceFile(netlifyGraphConfig)
Expand Down Expand Up @@ -1336,7 +1321,6 @@ const ensureCLISession = async (input) => {
// If we can't access the session in the state.json or it doesn't exist, create a new one
const sessionName = generateSessionName()
const detectedMetadata = await detectLocalCLISessionMetadata({
config,
siteRoot: site.root,
})
const newSessionMetadata = parentCliSessionId ? { parentCliSessionId } : {}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/one-graph/cli-netlify-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ const generateFunctionsFile = async ({ config, netlifyGraphConfig, operationsDoc

const codegenModule = await getCodegenModule({ config })
if (!codegenModule) {
error(
warn(
`No Netlify Graph codegen module specified in netlify.toml under the [graph] header. Please specify 'codeGenerator' field and try again.`,
)
return
Expand Down

1 comment on commit e9fa5e3

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

Please sign in to comment.