Skip to content
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
40 changes: 25 additions & 15 deletions graphql/codegen/src/core/codegen/cli/table-command-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,23 +536,33 @@ function buildMutationHandler(
// For create: field is required only if it has no default value
// For update: all fields are optional (user only updates what they want)
const isRequired = operation === 'create' && !fieldsWithDefaults.has(field.name);
questions.push(
t.objectExpression([
t.objectProperty(t.identifier('type'), t.stringLiteral('text')),
t.objectProperty(
t.identifier('name'),
t.stringLiteral(field.name),
),
t.objectProperty(
t.identifier('message'),
t.stringLiteral(field.name),
),
const hasDefault = fieldsWithDefaults.has(field.name);
const questionProps = [
t.objectProperty(t.identifier('type'), t.stringLiteral('text')),
t.objectProperty(
t.identifier('name'),
t.stringLiteral(field.name),
),
t.objectProperty(
t.identifier('message'),
t.stringLiteral(field.name),
),
t.objectProperty(
t.identifier('required'),
t.booleanLiteral(isRequired),
),
];
// Skip prompting for fields with backend-managed defaults.
// The field still appears in man pages and can be overridden via CLI flags.
if (hasDefault) {
questionProps.push(
t.objectProperty(
t.identifier('required'),
t.booleanLiteral(isRequired),
t.identifier('skipPrompt'),
t.booleanLiteral(true),
),
]),
);
);
}
questions.push(t.objectExpression(questionProps));
}
}

Expand Down
Loading