Skip to content

Commit ad31bb1

Browse files
committed
created getDirective function in values.js
1 parent 32500bf commit ad31bb1

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/execution/values.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,22 @@ export function getArgumentValues(
230230
return coercedValues;
231231
}
232232

233+
/**
234+
* If the directive does not exist on the node, returns undefined otherwise returns a DirectiveNode.
235+
*/
236+
export function getDirective(
237+
directiveDef: GraphQLDirective,
238+
node: { +directives?: $ReadOnlyArray<DirectiveNode>, ... },
239+
): void | DirectiveNode {
240+
return (
241+
node.directives &&
242+
find(
243+
node.directives,
244+
directive => directive.name.value === directiveDef.name,
245+
)
246+
);
247+
}
248+
233249
/**
234250
* Prepares an object map of argument values given a directive definition
235251
* and a AST node which may contain directives. Optionally also accepts a map
@@ -246,12 +262,7 @@ export function getDirectiveValues(
246262
node: { +directives?: $ReadOnlyArray<DirectiveNode>, ... },
247263
variableValues?: ?ObjMap<mixed>,
248264
): void | { [argument: string]: mixed, ... } {
249-
const directiveNode =
250-
node.directives &&
251-
find(
252-
node.directives,
253-
directive => directive.name.value === directiveDef.name,
254-
);
265+
const directiveNode = getDirective(directiveDef, node);
255266

256267
if (directiveNode) {
257268
return getArgumentValues(directiveDef, directiveNode, variableValues);

0 commit comments

Comments
 (0)