Skip to content

Commit

Permalink
feat: allow multiple operation names in graph:hander (#4978)
Browse files Browse the repository at this point in the history
* feat: allow multiple operation names in graph:hander

* fix: handle another place where list may be empty

* chore: docs

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
dwwoelfel and kodiakhq[bot] authored Aug 19, 2022
1 parent 2d4b68c commit cef0f45
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/commands/graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ netlify graph:handler

**Arguments**

- name - Operation name
- name - Operation name(s)

**Flags**

Expand Down
36 changes: 20 additions & 16 deletions src/commands/graph/graph-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ const graphHandler = async (args, options, command) => {
error(`Error parsing schema: ${buildSchemaError}`)
}

const userOperationName = args.operationName
const userOperationNames = args.operationNames
const userCodegenId = options.codegen

const handlerOptions = options.data ? JSON.parse(options.data) : {}

let operationName = userOperationName
if (!operationName) {
operationName = await autocompleteOperationNames({ netlifyGraphConfig })
let operationNames = userOperationNames
if (!operationNames || operationNames.length === 0) {
const operationName = await autocompleteOperationNames({ netlifyGraphConfig })
operationNames = [operationName]
}

if (!operationName) {
if (!operationNames || operationNames.length === 0) {
error(`No operation name provided`)
}

Expand All @@ -66,14 +67,17 @@ const graphHandler = async (args, options, command) => {
}

if (schema) {
generateHandlerByOperationName({
generate: codeGenerator.generateHandler,
logger: log,
netlifyGraphConfig,
schema,
operationName,
handlerOptions,
})
/* eslint-disable fp/no-loops */
for (const operationName of operationNames) {
await generateHandlerByOperationName({
generate: codeGenerator.generateHandler,
logger: log,
netlifyGraphConfig,
schema,
operationName,
handlerOptions,
})
}
} else {
error(`Failed to parse Netlify GraphQL schema`)
}
Expand All @@ -87,14 +91,14 @@ const graphHandler = async (args, options, command) => {
const createGraphHandlerCommand = (program) =>
program
.command('graph:handler')
.argument('[name]', 'Operation name')
.argument('[name...]', 'Operation name(s)')
.option('-c, --codegen <id>', 'The id of the specific code generator to use')
.option("-d, --data '<json>'", 'Optional data to pass along to the code generator')
.description(
'Generate a handler for a Graph operation given its name. See `graph:operations` for a list of operations.',
)
.action(async (operationName, options, command) => {
await graphHandler({ operationName }, options, command)
.action(async (operationNames, options, command) => {
await graphHandler({ operationNames }, options, command)
})

module.exports = { createGraphHandlerCommand }

1 comment on commit cef0f45

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