Skip to content

Commit

Permalink
fix(graph): make handler generation async/effectful (#4984)
Browse files Browse the repository at this point in the history
* feat: support --context in dev:exec

* feat: support envelope env vars with --context in `netlify build`

* chore: update contributors field

* chore: npm run docs

* chore: support context env var

* chore: wip

* chore: support branches as build context

* docs: npm run docs

* feat: convert Graph handler codegen to async

* chore(graph): update dep

Co-authored-by: Jason Barry <jb@netlify.com>
Co-authored-by: jasonbarry <jasonbarry@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 19, 2022
1 parent e0f1680 commit 2d4b68c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 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.1",
"netlify-headers-parser": "^6.0.2",
"netlify-onegraph-internal": "0.8.7",
"netlify-onegraph-internal": "0.10.0",
"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/dev/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ const dev = async (options, command) => {
}

let { env } = cachedConfig

if (!options.offline && siteInfo.use_envelope) {
env = await getEnvelopeEnv({ api, context: options.context, env, siteInfo })
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/one-graph/cli-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ const refetchAndGenerateFromOneGraph = async (input) => {
return
}

generateFunctionsFile({
await generateFunctionsFile({
config,
logger,
netlifyGraphConfig,
Expand Down Expand Up @@ -619,7 +619,7 @@ ${JSON.stringify(payload, null, 2)}`)
return
}

const files = generateHandlerByOperationId({
const files = await generateHandlerByOperationId({
netlifyGraphConfig,
schema,
operationId: payload.operationId,
Expand Down
18 changes: 9 additions & 9 deletions src/lib/one-graph/cli-netlify-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,9 @@ const readGraphQLSchemaFile = (netlifyGraphConfig) => {
* @param {string} input.operationsDoc The document containing the operation with operationId and any fragment dependency to use when generating the handler
* @param {object} input.handlerOptions The options to use when generating the handler
* @param {(message: string) => void=} input.logger A function that if provided will be used to log messages
* @returns {{exportedFiles: CodegenHelpers.ExportedFile[]; operation: GraphQL.OperationDefinitionNode;} | undefined} The generated files
* @returns {Promise<{exportedFiles: CodegenHelpers.ExportedFile[]; operation: GraphQL.OperationDefinitionNode;} | undefined>} The generated files
*/
const generateHandlerSourceByOperationId = ({
const generateHandlerSourceByOperationId = async ({
generate,
handlerOptions,
netlifyGraphConfig,
Expand All @@ -571,7 +571,7 @@ const generateHandlerSourceByOperationId = ({
operationsDoc,
}

const result = NetlifyGraph.generateCustomHandlerSource(generateHandlerPayload)
const result = await NetlifyGraph.generateCustomHandlerSource(generateHandlerPayload)

return result
}
Expand All @@ -585,15 +585,15 @@ const generateHandlerSourceByOperationId = ({
* @param {string} input.operationId The operationId to use when generating the handler
* @param {object} input.handlerOptions The options to use when generating the handler
* @param {(message: string) => void=} input.logger A function that if provided will be used to log messages
* @returns {Array<{filePath: string, name:string, prettierSuccess: boolean}> | undefined} An array of the generated handler filepaths
* @returns {Promise<Array<{filePath: string, name:string, prettierSuccess: boolean}> | undefined>} An array of the generated handler filepaths
*/
const generateHandlerByOperationId = ({ generate, handlerOptions, netlifyGraphConfig, operationId, schema }) => {
const generateHandlerByOperationId = async ({ generate, handlerOptions, netlifyGraphConfig, operationId, schema }) => {
let currentOperationsDoc = readGraphQLOperationsSourceFile(netlifyGraphConfig)
if (currentOperationsDoc.trim().length === 0) {
currentOperationsDoc = NetlifyGraph.defaultExampleOperationsDoc
}

const result = generateHandlerSourceByOperationId({
const result = await generateHandlerSourceByOperationId({
generate,
handlerOptions,
netlifyGraphConfig,
Expand Down Expand Up @@ -669,9 +669,9 @@ const generateHandlerByOperationId = ({ generate, handlerOptions, netlifyGraphCo
* @param {string} input.operationName The name of the operation to use when generating the handler
* @param {object} input.handlerOptions The options to use when generating the handler
* @param {(message: string) => void} input.logger A function that if provided will be used to log messages
* @returns
* @returns {Promise<void>}
*/
const generateHandlerByOperationName = ({
const generateHandlerByOperationName = async ({
generate,
handlerOptions,
logger,
Expand Down Expand Up @@ -702,7 +702,7 @@ const generateHandlerByOperationName = ({
return
}

generateHandlerByOperationId({
await generateHandlerByOperationId({
logger,
generate,
netlifyGraphConfig,
Expand Down

1 comment on commit 2d4b68c

@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.