@graphql-tools/utils 10.5.1 → 10.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,34 +5,43 @@ const graphql_1 = require("graphql");
5
5
  const getArgumentValues_js_1 = require("./getArgumentValues.js");
6
6
  function getDirectiveExtensions(directableObj, schema, pathToDirectivesInExtensions = ['directives']) {
7
7
  const directiveExtensions = {};
8
- if (directableObj.astNode?.directives?.length) {
9
- for (const directive of directableObj.astNode.directives) {
10
- const directiveName = directive.name.value;
11
- let existingDirectiveExtensions = directiveExtensions[directiveName];
12
- if (!existingDirectiveExtensions) {
13
- existingDirectiveExtensions = [];
14
- directiveExtensions[directiveName] = existingDirectiveExtensions;
15
- }
16
- const directiveInSchema = schema?.getDirective(directiveName);
17
- let value = {};
18
- if (directiveInSchema) {
19
- value = (0, getArgumentValues_js_1.getArgumentValues)(directiveInSchema, directive);
20
- }
21
- if (directive.arguments) {
22
- for (const argNode of directive.arguments) {
23
- const argName = argNode.name.value;
24
- if (value[argName] == null) {
25
- const argInDirective = directiveInSchema?.args.find(arg => arg.name === argName);
26
- if (argInDirective) {
27
- value[argName] = (0, graphql_1.valueFromAST)(argNode.value, argInDirective.type);
8
+ const astNodes = [];
9
+ if (directableObj.astNode) {
10
+ astNodes.push(directableObj.astNode);
11
+ }
12
+ if (directableObj.extensionASTNodes) {
13
+ astNodes.push(...directableObj.extensionASTNodes);
14
+ }
15
+ for (const astNode of astNodes) {
16
+ if (astNode.directives?.length) {
17
+ for (const directive of astNode.directives) {
18
+ const directiveName = directive.name.value;
19
+ let existingDirectiveExtensions = directiveExtensions[directiveName];
20
+ if (!existingDirectiveExtensions) {
21
+ existingDirectiveExtensions = [];
22
+ directiveExtensions[directiveName] = existingDirectiveExtensions;
23
+ }
24
+ const directiveInSchema = schema?.getDirective(directiveName);
25
+ let value = {};
26
+ if (directiveInSchema) {
27
+ value = (0, getArgumentValues_js_1.getArgumentValues)(directiveInSchema, directive);
28
+ }
29
+ if (directive.arguments) {
30
+ for (const argNode of directive.arguments) {
31
+ const argName = argNode.name.value;
32
+ if (value[argName] == null) {
33
+ const argInDirective = directiveInSchema?.args.find(arg => arg.name === argName);
34
+ if (argInDirective) {
35
+ value[argName] = (0, graphql_1.valueFromAST)(argNode.value, argInDirective.type);
36
+ }
37
+ }
38
+ if (value[argName] == null) {
39
+ value[argName] = (0, graphql_1.valueFromASTUntyped)(argNode.value);
28
40
  }
29
- }
30
- if (value[argName] == null) {
31
- value[argName] = (0, graphql_1.valueFromASTUntyped)(argNode.value);
32
41
  }
33
42
  }
43
+ existingDirectiveExtensions.push(value);
34
44
  }
35
- existingDirectiveExtensions.push(value);
36
45
  }
37
46
  }
38
47
  if (directableObj.extensions) {
@@ -2,34 +2,43 @@ import { valueFromAST, valueFromASTUntyped } from 'graphql';
2
2
  import { getArgumentValues } from './getArgumentValues.js';
3
3
  export function getDirectiveExtensions(directableObj, schema, pathToDirectivesInExtensions = ['directives']) {
4
4
  const directiveExtensions = {};
5
- if (directableObj.astNode?.directives?.length) {
6
- for (const directive of directableObj.astNode.directives) {
7
- const directiveName = directive.name.value;
8
- let existingDirectiveExtensions = directiveExtensions[directiveName];
9
- if (!existingDirectiveExtensions) {
10
- existingDirectiveExtensions = [];
11
- directiveExtensions[directiveName] = existingDirectiveExtensions;
12
- }
13
- const directiveInSchema = schema?.getDirective(directiveName);
14
- let value = {};
15
- if (directiveInSchema) {
16
- value = getArgumentValues(directiveInSchema, directive);
17
- }
18
- if (directive.arguments) {
19
- for (const argNode of directive.arguments) {
20
- const argName = argNode.name.value;
21
- if (value[argName] == null) {
22
- const argInDirective = directiveInSchema?.args.find(arg => arg.name === argName);
23
- if (argInDirective) {
24
- value[argName] = valueFromAST(argNode.value, argInDirective.type);
5
+ const astNodes = [];
6
+ if (directableObj.astNode) {
7
+ astNodes.push(directableObj.astNode);
8
+ }
9
+ if (directableObj.extensionASTNodes) {
10
+ astNodes.push(...directableObj.extensionASTNodes);
11
+ }
12
+ for (const astNode of astNodes) {
13
+ if (astNode.directives?.length) {
14
+ for (const directive of astNode.directives) {
15
+ const directiveName = directive.name.value;
16
+ let existingDirectiveExtensions = directiveExtensions[directiveName];
17
+ if (!existingDirectiveExtensions) {
18
+ existingDirectiveExtensions = [];
19
+ directiveExtensions[directiveName] = existingDirectiveExtensions;
20
+ }
21
+ const directiveInSchema = schema?.getDirective(directiveName);
22
+ let value = {};
23
+ if (directiveInSchema) {
24
+ value = getArgumentValues(directiveInSchema, directive);
25
+ }
26
+ if (directive.arguments) {
27
+ for (const argNode of directive.arguments) {
28
+ const argName = argNode.name.value;
29
+ if (value[argName] == null) {
30
+ const argInDirective = directiveInSchema?.args.find(arg => arg.name === argName);
31
+ if (argInDirective) {
32
+ value[argName] = valueFromAST(argNode.value, argInDirective.type);
33
+ }
34
+ }
35
+ if (value[argName] == null) {
36
+ value[argName] = valueFromASTUntyped(argNode.value);
25
37
  }
26
- }
27
- if (value[argName] == null) {
28
- value[argName] = valueFromASTUntyped(argNode.value);
29
38
  }
30
39
  }
40
+ existingDirectiveExtensions.push(value);
31
41
  }
32
- existingDirectiveExtensions.push(value);
33
42
  }
34
43
  }
35
44
  if (directableObj.extensions) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "10.5.1",
3
+ "version": "10.5.2",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -4,6 +4,7 @@ export type DirectableASTNode = ASTNode & {
4
4
  };
5
5
  export type DirectableObject = {
6
6
  astNode?: DirectableASTNode | null;
7
+ extensionASTNodes?: readonly DirectableASTNode[] | null;
7
8
  extensions?: {
8
9
  directives?: Record<string, any>;
9
10
  } | null;
@@ -4,6 +4,7 @@ export type DirectableASTNode = ASTNode & {
4
4
  };
5
5
  export type DirectableObject = {
6
6
  astNode?: DirectableASTNode | null;
7
+ extensionASTNodes?: readonly DirectableASTNode[] | null;
7
8
  extensions?: {
8
9
  directives?: Record<string, any>;
9
10
  } | null;