Skip to content

Commit 9a43d47

Browse files
Simplify args definition (#1650)
1 parent 126b572 commit 9a43d47

File tree

2 files changed

+27
-34
lines changed

2 files changed

+27
-34
lines changed

src/type/definition.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -728,23 +728,20 @@ function defineFieldMap<TSource, TContext>(
728728
`${config.name}.${fieldName} field resolver must be a function if ` +
729729
`provided, but got: ${inspect(field.resolve)}.`,
730730
);
731-
const argsConfig = fieldConfig.args;
732-
if (!argsConfig) {
733-
field.args = [];
734-
} else {
735-
invariant(
736-
isPlainObj(argsConfig),
737-
`${config.name}.${fieldName} args must be an object with argument ` +
738-
'names as keys.',
739-
);
740-
field.args = objectEntries(argsConfig).map(([argName, arg]) => ({
741-
name: argName,
742-
description: arg.description === undefined ? null : arg.description,
743-
type: arg.type,
744-
defaultValue: arg.defaultValue,
745-
astNode: arg.astNode,
746-
}));
747-
}
731+
const argsConfig = fieldConfig.args || {};
732+
invariant(
733+
isPlainObj(argsConfig),
734+
`${config.name}.${fieldName} args must be an object with argument ` +
735+
'names as keys.',
736+
);
737+
738+
field.args = objectEntries(argsConfig).map(([argName, arg]) => ({
739+
name: argName,
740+
description: arg.description === undefined ? null : arg.description,
741+
type: arg.type,
742+
defaultValue: arg.defaultValue,
743+
astNode: arg.astNode,
744+
}));
748745
resultFieldMap[fieldName] = field;
749746
}
750747
return resultFieldMap;

src/type/directives.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,19 @@ export class GraphQLDirective {
6666
'Must provide locations for directive.',
6767
);
6868

69-
const args = config.args;
70-
if (!args) {
71-
this.args = [];
72-
} else {
73-
invariant(
74-
!Array.isArray(args),
75-
`@${config.name} args must be an object with argument names as keys.`,
76-
);
77-
78-
this.args = objectEntries(args).map(([argName, arg]) => ({
79-
name: argName,
80-
description: arg.description === undefined ? null : arg.description,
81-
type: arg.type,
82-
defaultValue: arg.defaultValue,
83-
astNode: arg.astNode,
84-
}));
85-
}
69+
const args = config.args || {};
70+
invariant(
71+
!Array.isArray(args),
72+
`@${config.name} args must be an object with argument names as keys.`,
73+
);
74+
75+
this.args = objectEntries(args).map(([argName, arg]) => ({
76+
name: argName,
77+
description: arg.description === undefined ? null : arg.description,
78+
type: arg.type,
79+
defaultValue: arg.defaultValue,
80+
astNode: arg.astNode,
81+
}));
8682
}
8783

8884
toString(): string {

0 commit comments

Comments
 (0)