@graphql-tools/utils
Advanced tools
Comparing version 10.4.0-alpha-20240709213044-006da37e240c6ccb1d305e19ade18dd70384cb22 to 10.4.0-alpha-20240804112853-812acba5ea59541106a53f872874fd7aebcffcfc
@@ -25,5 +25,6 @@ "use strict"; | ||
} | ||
if (incrementalResult.items) { | ||
if (incrementalResult.id) { | ||
const id = incrementalResult.id; | ||
const items = incrementalResult.items; | ||
if (items) { | ||
const id = incrementalResult.id; | ||
if (id) { | ||
path = pathsMap.get(executionResult)?.get(id); | ||
@@ -34,7 +35,7 @@ if (path === undefined) { | ||
const list = (0, dlv_1.default)(executionResult, path); | ||
list.push(...incrementalResult.items); | ||
list.push(...items); | ||
} | ||
else { | ||
const path = ['data', ...(incrementalResult.path ?? [])]; | ||
for (const item of incrementalResult.items) { | ||
for (const item of items) { | ||
(0, merge_1.dset)(executionResult, path, item); | ||
@@ -46,13 +47,12 @@ // Increment the last path segment (the array index) to merge the next item at the next index | ||
} | ||
if (incrementalResult.data) { | ||
if (incrementalResult.id) { | ||
const id = incrementalResult.id; | ||
if (id !== undefined) { | ||
path = pathsMap.get(executionResult)?.get(id); | ||
if (path === undefined) { | ||
throw new Error('Invalid incremental delivery format.'); | ||
} | ||
const data = incrementalResult.data; | ||
if (data) { | ||
const id = incrementalResult.id; | ||
if (id) { | ||
path = pathsMap.get(executionResult)?.get(id); | ||
if (path === undefined) { | ||
throw new Error('Invalid incremental delivery format.'); | ||
} | ||
} | ||
(0, merge_1.dset)(executionResult, path, incrementalResult.data); | ||
(0, merge_1.dset)(executionResult, path, data); | ||
} | ||
@@ -59,0 +59,0 @@ if (incrementalResult.errors) { |
@@ -201,3 +201,3 @@ "use strict"; | ||
defaultValue: arg.defaultValue !== undefined | ||
? (0, astFromValue_js_1.astFromValue)(arg.defaultValue, arg.type) ?? undefined | ||
? ((0, astFromValue_js_1.astFromValue)(arg.defaultValue, arg.type) ?? undefined) | ||
: undefined, | ||
@@ -204,0 +204,0 @@ directives: getDeprecatableDirectiveNodes(arg, schema, pathToDirectivesInExtensions), |
@@ -108,8 +108,3 @@ "use strict"; | ||
// Visit enum values directives argument types | ||
queue.push(...type.getValues().flatMap(value => { | ||
if (value.astNode) { | ||
return getDirectivesArgumentsTypeNames(schema, value.astNode); | ||
} | ||
return []; | ||
})); | ||
queue.push(...type.getValues().flatMap(value => getDirectivesArgumentsTypeNames(schema, value))); | ||
} | ||
@@ -133,5 +128,3 @@ // Visit interfaces this type is implementing if they haven't been visited yet | ||
const typeNames = [(0, graphql_1.getNamedType)(arg.type).name]; | ||
if (arg.astNode) { | ||
typeNames.push(...getDirectivesArgumentsTypeNames(schema, arg.astNode)); | ||
} | ||
typeNames.push(...getDirectivesArgumentsTypeNames(schema, arg)); | ||
return typeNames; | ||
@@ -142,5 +135,3 @@ })); | ||
queue.push(namedType.name); | ||
if (field.astNode) { | ||
queue.push(...getDirectivesArgumentsTypeNames(schema, field.astNode)); | ||
} | ||
queue.push(...getDirectivesArgumentsTypeNames(schema, field)); | ||
// Interfaces returned on fields need to be revisited to add their implementations | ||
@@ -152,5 +143,3 @@ if ((0, graphql_1.isInterfaceType)(namedType) && !(namedType.name in revisit)) { | ||
} | ||
if (type.astNode) { | ||
queue.push(...getDirectivesArgumentsTypeNames(schema, type.astNode)); | ||
} | ||
queue.push(...getDirectivesArgumentsTypeNames(schema, type)); | ||
visited.add(typeName); // Mark as visited (and therefore it is used and should be kept) | ||
@@ -161,4 +150,27 @@ } | ||
} | ||
function getDirectivesArgumentsTypeNames(schema, astNode) { | ||
return (astNode.directives ?? []).flatMap(directive => schema.getDirective(directive.name.value)?.args.map(arg => (0, graphql_1.getNamedType)(arg.type).name) ?? []); | ||
function getDirectivesArgumentsTypeNames(schema, directableObj) { | ||
const argTypeNames = new Set(); | ||
if (directableObj.astNode?.directives) { | ||
for (const directiveNode of directableObj.astNode.directives) { | ||
const directive = schema.getDirective(directiveNode.name.value); | ||
if (directive?.args) { | ||
for (const arg of directive.args) { | ||
const argType = (0, graphql_1.getNamedType)(arg.type); | ||
argTypeNames.add(argType.name); | ||
} | ||
} | ||
} | ||
} | ||
if (directableObj.extensions?.['directives']) { | ||
for (const directiveName in directableObj.extensions['directives']) { | ||
const directive = schema.getDirective(directiveName); | ||
if (directive?.args) { | ||
for (const arg of directive.args) { | ||
const argType = (0, graphql_1.getNamedType)(arg.type); | ||
argTypeNames.add(argType.name); | ||
} | ||
} | ||
} | ||
} | ||
return [...argTypeNames]; | ||
} |
@@ -1,2 +0,2 @@ | ||
import dlv from 'dlv'; | ||
import delve from 'dlv'; | ||
import { dset } from 'dset/merge'; | ||
@@ -21,5 +21,6 @@ const pathsMap = new WeakMap(); | ||
} | ||
if (incrementalResult.items) { | ||
if (incrementalResult.id) { | ||
const id = incrementalResult.id; | ||
const items = incrementalResult.items; | ||
if (items) { | ||
const id = incrementalResult.id; | ||
if (id) { | ||
path = pathsMap.get(executionResult)?.get(id); | ||
@@ -29,8 +30,8 @@ if (path === undefined) { | ||
} | ||
const list = dlv(executionResult, path); | ||
list.push(...incrementalResult.items); | ||
const list = delve(executionResult, path); | ||
list.push(...items); | ||
} | ||
else { | ||
const path = ['data', ...(incrementalResult.path ?? [])]; | ||
for (const item of incrementalResult.items) { | ||
for (const item of items) { | ||
dset(executionResult, path, item); | ||
@@ -42,13 +43,12 @@ // Increment the last path segment (the array index) to merge the next item at the next index | ||
} | ||
if (incrementalResult.data) { | ||
if (incrementalResult.id) { | ||
const id = incrementalResult.id; | ||
if (id !== undefined) { | ||
path = pathsMap.get(executionResult)?.get(id); | ||
if (path === undefined) { | ||
throw new Error('Invalid incremental delivery format.'); | ||
} | ||
const data = incrementalResult.data; | ||
if (data) { | ||
const id = incrementalResult.id; | ||
if (id) { | ||
path = pathsMap.get(executionResult)?.get(id); | ||
if (path === undefined) { | ||
throw new Error('Invalid incremental delivery format.'); | ||
} | ||
} | ||
dset(executionResult, path, incrementalResult.data); | ||
dset(executionResult, path, data); | ||
} | ||
@@ -55,0 +55,0 @@ if (incrementalResult.errors) { |
@@ -192,3 +192,3 @@ import { GraphQLDeprecatedDirective, isEnumType, isInputObjectType, isInterfaceType, isIntrospectionType, isObjectType, isScalarType, isSpecifiedDirective, isSpecifiedScalarType, isUnionType, Kind, print, } from 'graphql'; | ||
defaultValue: arg.defaultValue !== undefined | ||
? astFromValue(arg.defaultValue, arg.type) ?? undefined | ||
? (astFromValue(arg.defaultValue, arg.type) ?? undefined) | ||
: undefined, | ||
@@ -195,0 +195,0 @@ directives: getDeprecatableDirectiveNodes(arg, schema, pathToDirectivesInExtensions), |
@@ -104,8 +104,3 @@ import { getNamedType, isEnumType, isInputObjectType, isInterfaceType, isObjectType, isScalarType, isSpecifiedScalarType, isUnionType, } from 'graphql'; | ||
// Visit enum values directives argument types | ||
queue.push(...type.getValues().flatMap(value => { | ||
if (value.astNode) { | ||
return getDirectivesArgumentsTypeNames(schema, value.astNode); | ||
} | ||
return []; | ||
})); | ||
queue.push(...type.getValues().flatMap(value => getDirectivesArgumentsTypeNames(schema, value))); | ||
} | ||
@@ -129,5 +124,3 @@ // Visit interfaces this type is implementing if they haven't been visited yet | ||
const typeNames = [getNamedType(arg.type).name]; | ||
if (arg.astNode) { | ||
typeNames.push(...getDirectivesArgumentsTypeNames(schema, arg.astNode)); | ||
} | ||
typeNames.push(...getDirectivesArgumentsTypeNames(schema, arg)); | ||
return typeNames; | ||
@@ -138,5 +131,3 @@ })); | ||
queue.push(namedType.name); | ||
if (field.astNode) { | ||
queue.push(...getDirectivesArgumentsTypeNames(schema, field.astNode)); | ||
} | ||
queue.push(...getDirectivesArgumentsTypeNames(schema, field)); | ||
// Interfaces returned on fields need to be revisited to add their implementations | ||
@@ -148,5 +139,3 @@ if (isInterfaceType(namedType) && !(namedType.name in revisit)) { | ||
} | ||
if (type.astNode) { | ||
queue.push(...getDirectivesArgumentsTypeNames(schema, type.astNode)); | ||
} | ||
queue.push(...getDirectivesArgumentsTypeNames(schema, type)); | ||
visited.add(typeName); // Mark as visited (and therefore it is used and should be kept) | ||
@@ -157,4 +146,27 @@ } | ||
} | ||
function getDirectivesArgumentsTypeNames(schema, astNode) { | ||
return (astNode.directives ?? []).flatMap(directive => schema.getDirective(directive.name.value)?.args.map(arg => getNamedType(arg.type).name) ?? []); | ||
function getDirectivesArgumentsTypeNames(schema, directableObj) { | ||
const argTypeNames = new Set(); | ||
if (directableObj.astNode?.directives) { | ||
for (const directiveNode of directableObj.astNode.directives) { | ||
const directive = schema.getDirective(directiveNode.name.value); | ||
if (directive?.args) { | ||
for (const arg of directive.args) { | ||
const argType = getNamedType(arg.type); | ||
argTypeNames.add(argType.name); | ||
} | ||
} | ||
} | ||
} | ||
if (directableObj.extensions?.['directives']) { | ||
for (const directiveName in directableObj.extensions['directives']) { | ||
const directive = schema.getDirective(directiveName); | ||
if (directive?.args) { | ||
for (const arg of directive.args) { | ||
const argType = getNamedType(arg.type); | ||
argTypeNames.add(argType.name); | ||
} | ||
} | ||
} | ||
} | ||
return [...argTypeNames]; | ||
} |
{ | ||
"name": "@graphql-tools/utils", | ||
"version": "10.4.0-alpha-20240709213044-006da37e240c6ccb1d305e19ade18dd70384cb22", | ||
"version": "10.4.0-alpha-20240804112853-812acba5ea59541106a53f872874fd7aebcffcfc", | ||
"description": "Common package containing utils and types for GraphQL tools", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
510802
11077