Skip to content

Commit

Permalink
minor fixes from PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasobrien99 committed Feb 6, 2025
1 parent 4ceadba commit 526f7c5
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
const { directives } = node;
const hasOneOfDirective = directives.some((directive) => directive.name.value === 'oneOf');

if (node.fields && hasOneOfDirective) {
if (node.fields && node.fields.length > 0 && hasOneOfDirective) {
const field = node.fields[0];
const value = generateMockValue({
typeName: fieldName,
Expand All @@ -754,19 +754,15 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
mockFieldsString = ` ...(override ? override : {${field.name.value} : ${value}}),`;
} else if (node.fields) {
mockFieldsString = node.fields
.map((field, index) => {
.map((field) => {
const value = generateMockValue({
typeName: fieldName,
fieldName: field.name.value,
currentType: field.type,
...sharedGenerateMockOpts,
});

const valueWithOverride = `overrides && overrides.hasOwnProperty('${
field.name.value
}') ? overrides.${field.name.value}! : ${
!hasOneOfDirective || index === 0 ? value : 'undefined'
}`;
const valueWithOverride = `overrides && overrides.hasOwnProperty('${field.name.value}') ? overrides.${field.name.value}! : ${value}`;

return ` ${field.name.value}: ${valueWithOverride},`;
})
Expand Down

0 comments on commit 526f7c5

Please sign in to comment.