@graphql-tools/utils 10.3.1 → 10.3.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.
Files changed (3) hide show
  1. package/cjs/prune.js +29 -17
  2. package/esm/prune.js +29 -17
  3. package/package.json +1 -1
package/cjs/prune.js CHANGED
@@ -105,12 +105,7 @@ function visitQueue(queue, schema, visited = new Set()) {
105
105
  }
106
106
  if ((0, graphql_1.isEnumType)(type)) {
107
107
  // Visit enum values directives argument types
108
- queue.push(...type.getValues().flatMap(value => {
109
- if (value.astNode) {
110
- return getDirectivesArgumentsTypeNames(schema, value.astNode);
111
- }
112
- return [];
113
- }));
108
+ queue.push(...type.getValues().flatMap(value => getDirectivesArgumentsTypeNames(schema, value)));
114
109
  }
115
110
  // Visit interfaces this type is implementing if they haven't been visited yet
116
111
  if ('getInterfaces' in type) {
@@ -129,31 +124,48 @@ function visitQueue(queue, schema, visited = new Set()) {
129
124
  // Visit arg types and arg directives arguments types
130
125
  queue.push(...field.args.flatMap(arg => {
131
126
  const typeNames = [(0, graphql_1.getNamedType)(arg.type).name];
132
- if (arg.astNode) {
133
- typeNames.push(...getDirectivesArgumentsTypeNames(schema, arg.astNode));
134
- }
127
+ typeNames.push(...getDirectivesArgumentsTypeNames(schema, arg));
135
128
  return typeNames;
136
129
  }));
137
130
  }
138
131
  const namedType = (0, graphql_1.getNamedType)(field.type);
139
132
  queue.push(namedType.name);
140
- if (field.astNode) {
141
- queue.push(...getDirectivesArgumentsTypeNames(schema, field.astNode));
142
- }
133
+ queue.push(...getDirectivesArgumentsTypeNames(schema, field));
143
134
  // Interfaces returned on fields need to be revisited to add their implementations
144
135
  if ((0, graphql_1.isInterfaceType)(namedType) && !(namedType.name in revisit)) {
145
136
  revisit[namedType.name] = true;
146
137
  }
147
138
  }
148
139
  }
149
- if (type.astNode) {
150
- queue.push(...getDirectivesArgumentsTypeNames(schema, type.astNode));
151
- }
140
+ queue.push(...getDirectivesArgumentsTypeNames(schema, type));
152
141
  visited.add(typeName); // Mark as visited (and therefore it is used and should be kept)
153
142
  }
154
143
  }
155
144
  return visited;
156
145
  }
157
- function getDirectivesArgumentsTypeNames(schema, astNode) {
158
- return (astNode.directives ?? []).flatMap(directive => schema.getDirective(directive.name.value)?.args.map(arg => (0, graphql_1.getNamedType)(arg.type).name) ?? []);
146
+ function getDirectivesArgumentsTypeNames(schema, directableObj) {
147
+ const argTypeNames = new Set();
148
+ if (directableObj.astNode?.directives) {
149
+ for (const directiveNode of directableObj.astNode.directives) {
150
+ const directive = schema.getDirective(directiveNode.name.value);
151
+ if (directive?.args) {
152
+ for (const arg of directive.args) {
153
+ const argType = (0, graphql_1.getNamedType)(arg.type);
154
+ argTypeNames.add(argType.name);
155
+ }
156
+ }
157
+ }
158
+ }
159
+ if (directableObj.extensions?.['directives']) {
160
+ for (const directiveName in directableObj.extensions['directives']) {
161
+ const directive = schema.getDirective(directiveName);
162
+ if (directive?.args) {
163
+ for (const arg of directive.args) {
164
+ const argType = (0, graphql_1.getNamedType)(arg.type);
165
+ argTypeNames.add(argType.name);
166
+ }
167
+ }
168
+ }
169
+ }
170
+ return [...argTypeNames];
159
171
  }
package/esm/prune.js CHANGED
@@ -101,12 +101,7 @@ function visitQueue(queue, schema, visited = new Set()) {
101
101
  }
102
102
  if (isEnumType(type)) {
103
103
  // Visit enum values directives argument types
104
- queue.push(...type.getValues().flatMap(value => {
105
- if (value.astNode) {
106
- return getDirectivesArgumentsTypeNames(schema, value.astNode);
107
- }
108
- return [];
109
- }));
104
+ queue.push(...type.getValues().flatMap(value => getDirectivesArgumentsTypeNames(schema, value)));
110
105
  }
111
106
  // Visit interfaces this type is implementing if they haven't been visited yet
112
107
  if ('getInterfaces' in type) {
@@ -125,31 +120,48 @@ function visitQueue(queue, schema, visited = new Set()) {
125
120
  // Visit arg types and arg directives arguments types
126
121
  queue.push(...field.args.flatMap(arg => {
127
122
  const typeNames = [getNamedType(arg.type).name];
128
- if (arg.astNode) {
129
- typeNames.push(...getDirectivesArgumentsTypeNames(schema, arg.astNode));
130
- }
123
+ typeNames.push(...getDirectivesArgumentsTypeNames(schema, arg));
131
124
  return typeNames;
132
125
  }));
133
126
  }
134
127
  const namedType = getNamedType(field.type);
135
128
  queue.push(namedType.name);
136
- if (field.astNode) {
137
- queue.push(...getDirectivesArgumentsTypeNames(schema, field.astNode));
138
- }
129
+ queue.push(...getDirectivesArgumentsTypeNames(schema, field));
139
130
  // Interfaces returned on fields need to be revisited to add their implementations
140
131
  if (isInterfaceType(namedType) && !(namedType.name in revisit)) {
141
132
  revisit[namedType.name] = true;
142
133
  }
143
134
  }
144
135
  }
145
- if (type.astNode) {
146
- queue.push(...getDirectivesArgumentsTypeNames(schema, type.astNode));
147
- }
136
+ queue.push(...getDirectivesArgumentsTypeNames(schema, type));
148
137
  visited.add(typeName); // Mark as visited (and therefore it is used and should be kept)
149
138
  }
150
139
  }
151
140
  return visited;
152
141
  }
153
- function getDirectivesArgumentsTypeNames(schema, astNode) {
154
- return (astNode.directives ?? []).flatMap(directive => schema.getDirective(directive.name.value)?.args.map(arg => getNamedType(arg.type).name) ?? []);
142
+ function getDirectivesArgumentsTypeNames(schema, directableObj) {
143
+ const argTypeNames = new Set();
144
+ if (directableObj.astNode?.directives) {
145
+ for (const directiveNode of directableObj.astNode.directives) {
146
+ const directive = schema.getDirective(directiveNode.name.value);
147
+ if (directive?.args) {
148
+ for (const arg of directive.args) {
149
+ const argType = getNamedType(arg.type);
150
+ argTypeNames.add(argType.name);
151
+ }
152
+ }
153
+ }
154
+ }
155
+ if (directableObj.extensions?.['directives']) {
156
+ for (const directiveName in directableObj.extensions['directives']) {
157
+ const directive = schema.getDirective(directiveName);
158
+ if (directive?.args) {
159
+ for (const arg of directive.args) {
160
+ const argType = getNamedType(arg.type);
161
+ argTypeNames.add(argType.name);
162
+ }
163
+ }
164
+ }
165
+ }
166
+ return [...argTypeNames];
155
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "10.3.1",
3
+ "version": "10.3.2",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {