@graphql-toolkit/core
Advanced tools
Comparing version 0.10.3-alpha-d33816a.8 to 0.10.3-alpha-e61b7c0.6
@@ -36,3 +36,3 @@ import { DefinitionNode, DocumentNode } from 'graphql'; | ||
* | ||
* @param documentSource File path to the initial schema file | ||
* @param filePath File path to the initial schema file | ||
* @returns Single bundled schema with all imported types | ||
@@ -39,0 +39,0 @@ */ |
@@ -521,6 +521,5 @@ 'use strict'; | ||
while (newTypeDefinitions.length > 0) { | ||
const schemaMap = lodash.keyBy(lodash.reverse(allDefinitions), (d) => ('name' in d ? d.name.value : 'schema')); | ||
const schemaMap = lodash.keyBy(lodash.reverse(allDefinitions), d => ('name' in d ? d.name.value : 'schema')); | ||
const newDefinition = newTypeDefinitions.shift(); | ||
const defName = 'name' in newDefinition ? newDefinition.name.value : 'schema'; | ||
if (visitedDefinitions[defName]) { | ||
if (visitedDefinitions['name' in newDefinition ? newDefinition.name.value : 'schema']) { | ||
continue; | ||
@@ -531,3 +530,3 @@ } | ||
definitionPool.push(...collectedTypedDefinitions); | ||
visitedDefinitions[defName] = true; | ||
visitedDefinitions['name' in newDefinition ? newDefinition.name.value : 'schema'] = true; | ||
} | ||
@@ -551,20 +550,20 @@ return lodash.uniqBy(definitionPool, 'name.value'); | ||
let newTypeDefinitions = []; | ||
if (newDefinition.kind !== graphql.Kind.DIRECTIVE_DEFINITION) { | ||
if (newDefinition.kind !== 'DirectiveDefinition') { | ||
newDefinition.directives.forEach(collectDirective); | ||
} | ||
if (newDefinition.kind === graphql.Kind.ENUM_TYPE_DEFINITION) { | ||
newDefinition.values.forEach((value) => value.directives.forEach(collectDirective)); | ||
if (newDefinition.kind === 'EnumTypeDefinition') { | ||
newDefinition.values.forEach(value => value.directives.forEach(collectDirective)); | ||
} | ||
if (newDefinition.kind === graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION) { | ||
if (newDefinition.kind === 'InputObjectTypeDefinition') { | ||
newDefinition.fields.forEach(collectNode); | ||
} | ||
if (newDefinition.kind === graphql.Kind.INTERFACE_TYPE_DEFINITION) { | ||
if (newDefinition.kind === 'InterfaceTypeDefinition') { | ||
const interfaceName = newDefinition.name.value; | ||
newDefinition.fields.forEach(collectNode); | ||
const interfaceImplementations = allDefinitions.filter((d) => d.kind === graphql.Kind.OBJECT_TYPE_DEFINITION && d.interfaces.some((i) => i.name.value === interfaceName)); | ||
const interfaceImplementations = allDefinitions.filter(d => d.kind === 'ObjectTypeDefinition' && d.interfaces.some(i => i.name.value === interfaceName)); | ||
newTypeDefinitions.push(...interfaceImplementations); | ||
} | ||
if (newDefinition.kind === graphql.Kind.UNION_TYPE_DEFINITION) { | ||
newDefinition.types.forEach((type) => { | ||
if (!definitionPool.some((d) => 'name' in d && d.name.value === type.name.value)) { | ||
if (newDefinition.kind === 'UnionTypeDefinition') { | ||
newDefinition.types.forEach(type => { | ||
if (!definitionPool.some(d => 'name' in d && d.name.value === type.name.value)) { | ||
const typeName = type.name.value; | ||
@@ -579,6 +578,6 @@ const typeMatch = schemaMap[typeName]; | ||
} | ||
if (newDefinition.kind === graphql.Kind.OBJECT_TYPE_DEFINITION) { | ||
if (newDefinition.kind === 'ObjectTypeDefinition') { | ||
// collect missing interfaces | ||
newDefinition.interfaces.forEach((int) => { | ||
if (!definitionPool.some((d) => 'name' in d && d.name.value === int.name.value)) { | ||
newDefinition.interfaces.forEach(int => { | ||
if (!definitionPool.some(d => 'name' in d && d.name.value === int.name.value)) { | ||
const interfaceName = int.name.value; | ||
@@ -593,3 +592,3 @@ const interfaceMatch = schemaMap[interfaceName]; | ||
// iterate over all fields | ||
newDefinition.fields.forEach((field) => { | ||
newDefinition.fields.forEach(field => { | ||
collectNode(field); | ||
@@ -600,5 +599,5 @@ // collect missing argument input types | ||
} | ||
if (newDefinition.kind === graphql.Kind.SCHEMA_DEFINITION) { | ||
newDefinition.operationTypes.forEach((operationType) => { | ||
if (!definitionPool.some((d) => 'name' in d && d.name.value === operationType.type.name.value)) { | ||
if (newDefinition.kind === 'SchemaDefinition') { | ||
newDefinition.operationTypes.forEach(operationType => { | ||
if (!definitionPool.some(d => 'name' in d && d.name.value === operationType.type.name.value)) { | ||
const typeName = operationType.type.name.value; | ||
@@ -624,3 +623,3 @@ const typeMatch = schemaMap[typeName]; | ||
const fragmentName = node.name.value; | ||
if (!definitionPool.some((d) => 'name' in d && d.name.value === fragmentName)) { | ||
if (!definitionPool.some(d => 'name' in d && d.name.value === fragmentName)) { | ||
const fragmentMatch = schemaMap[fragmentName]; | ||
@@ -646,3 +645,3 @@ if (!fragmentMatch) { | ||
// collect missing argument input types | ||
if (!definitionPool.some((d) => 'name' in d && d.name.value === nodeTypeName) && | ||
if (!definitionPool.some(d => 'name' in d && d.name.value === nodeTypeName) && | ||
!lodash.includes(builtinTypes, nodeTypeName)) { | ||
@@ -659,3 +658,3 @@ const argTypeMatch = schemaMap[nodeTypeName]; | ||
const directiveName = directive.name.value; | ||
if (!definitionPool.some((d) => 'name' in d && d.name.value === directiveName) && | ||
if (!definitionPool.some(d => 'name' in d && d.name.value === directiveName) && | ||
!lodash.includes(builtinDirectives, directiveName)) { | ||
@@ -678,3 +677,3 @@ const directive = schemaMap[directiveName]; | ||
function getNamedType(type) { | ||
if (type.kind === graphql.Kind.NAMED_TYPE) { | ||
if (type.kind === 'NamedType') { | ||
return type; | ||
@@ -685,2 +684,3 @@ } | ||
const rootFields = ['Query', 'Mutation', 'Subscription']; | ||
const gqlExt = /\.g(raph)?ql(s)?$/; | ||
@@ -706,3 +706,3 @@ function isGraphQLFile(f) { | ||
// Extract imported types | ||
const imports = wildcard === '*' ? ['*'] : importsString.split(',').map((d) => d.trim()); | ||
const imports = wildcard === '*' ? ['*'] : importsString.split(',').map(d => d.trim()); | ||
// Return information about the import line | ||
@@ -732,5 +732,5 @@ return { imports, from }; | ||
.split('\n') | ||
.map((l) => l.trim()) | ||
.filter((l) => l.startsWith('# import ') || l.startsWith('#import ')) | ||
.map((l) => l.replace('#', '').trim()) | ||
.map(l => l.trim()) | ||
.filter(l => l.startsWith('# import ') || l.startsWith('#import ')) | ||
.map(l => l.replace('#', '').trim()) | ||
.map(parseImportLine); | ||
@@ -757,3 +757,3 @@ } | ||
* | ||
* @param documentSource File path to the initial schema file | ||
* @param filePath File path to the initial schema file | ||
* @returns Single bundled schema with all imported types | ||
@@ -771,2 +771,3 @@ */ | ||
} | ||
// | ||
function process$1({ typeDefinitions, options, allDefinitions, }) { | ||
@@ -790,3 +791,3 @@ // Post processing of the final schema (missing types, unused types, etc.) | ||
else { | ||
const existingType = mergedFirstTypes.find((t) => t.name.value === type.name.value); | ||
const existingType = mergedFirstTypes.find(t => t.name.value === type.name.value); | ||
if ('fields' in existingType) { | ||
@@ -828,4 +829,4 @@ existingType.fields = lodash.uniqBy(existingType.fields.concat(type.fields), 'name.value'); | ||
.split('\n') | ||
.map((l) => l.trim()) | ||
.filter((l) => !(l.length === 0 || l.startsWith('#'))).length === 0); | ||
.map(l => l.trim()) | ||
.filter(l => !(l.length === 0 || l.startsWith('#'))).length === 0); | ||
} | ||
@@ -905,3 +906,3 @@ /** | ||
// Process each file (recursively) | ||
rawModules.forEach((module) => { | ||
rawModules.forEach(module => { | ||
// If it was not yet processed (in case of circular dependencies) | ||
@@ -932,3 +933,3 @@ const filepath = resolveModuleFilePath(source.location, module.from, options); | ||
const processedFile = options.processedFiles.get(filepath); | ||
if (!processedFile || !processedFile.find((rModule) => lodash.isEqual(rModule, module))) { | ||
if (!processedFile || !processedFile.find(rModule => lodash.isEqual(rModule, module))) { | ||
// Mark this specific import line as processed for this file (for cicular dependency cases) | ||
@@ -953,4 +954,4 @@ options.processedFiles.set(filepath, processedFile ? processedFile.concat(module) : [module]); | ||
if (imports.length === 1 && imports[0] === '*' && allDefinitions.length > 1) { | ||
const previousTypeDefinitions = lodash.keyBy(lodash.flatten(allDefinitions.slice(0, allDefinitions.length - 1)).filter((def) => 'name' in def), (def) => 'name' in def && def.name.value); | ||
return typeDefinitions.filter((typeDef) => typeDef.kind === 'ObjectTypeDefinition' && previousTypeDefinitions[typeDef.name.value]); | ||
const previousTypeDefinitions = lodash.keyBy(lodash.flatten(allDefinitions.slice(0, allDefinitions.length - 1)).filter(def => 'name' in def && !rootFields.includes(def.name.value)), def => 'name' in def && def.name.value); | ||
return typeDefinitions.filter(typeDef => typeDef.kind === 'ObjectTypeDefinition' && previousTypeDefinitions[typeDef.name.value]); | ||
} | ||
@@ -960,9 +961,9 @@ return filteredDefinitions; | ||
else { | ||
const importedTypes = imports.map((i) => i.split('.')[0]); | ||
const result = filteredDefinitions.filter((d) => 'name' in d && importedTypes.includes(d.name.value)); | ||
const fieldImports = imports.filter((i) => i.split('.').length > 1); | ||
const groupedFieldImports = lodash.groupBy(fieldImports, (x) => x.split('.')[0]); | ||
const importedTypes = imports.map(i => i.split('.')[0]); | ||
const result = filteredDefinitions.filter(d => 'name' in d && importedTypes.includes(d.name.value)); | ||
const fieldImports = imports.filter(i => i.split('.').length > 1); | ||
const groupedFieldImports = lodash.groupBy(fieldImports, x => x.split('.')[0]); | ||
for (const rootType in groupedFieldImports) { | ||
const fields = groupedFieldImports[rootType].map((x) => x.split('.')[1]); | ||
const objectTypeDefinition = filteredDefinitions.find((def) => 'name' in def && def.name.value === rootType); | ||
const fields = groupedFieldImports[rootType].map(x => x.split('.')[1]); | ||
const objectTypeDefinition = filteredDefinitions.find(def => 'name' in def && def.name.value === rootType); | ||
if (objectTypeDefinition && 'fields' in objectTypeDefinition && !fields.includes('*')) { | ||
@@ -969,0 +970,0 @@ objectTypeDefinition.fields = objectTypeDefinition.fields.filter((f) => fields.includes(f.name.value) || fields.includes('*')); |
@@ -496,6 +496,5 @@ import { asArray, resolveBuiltinModule, resolveBuiltinModuleSync, debugLog, printSchemaWithDirectives, isDocumentString, parseGraphQLSDL, compareNodes, fixSchemaAst, compareStrings } from '@graphql-toolkit/common'; | ||
while (newTypeDefinitions.length > 0) { | ||
const schemaMap = keyBy(reverse(allDefinitions), (d) => ('name' in d ? d.name.value : 'schema')); | ||
const schemaMap = keyBy(reverse(allDefinitions), d => ('name' in d ? d.name.value : 'schema')); | ||
const newDefinition = newTypeDefinitions.shift(); | ||
const defName = 'name' in newDefinition ? newDefinition.name.value : 'schema'; | ||
if (visitedDefinitions[defName]) { | ||
if (visitedDefinitions['name' in newDefinition ? newDefinition.name.value : 'schema']) { | ||
continue; | ||
@@ -506,3 +505,3 @@ } | ||
definitionPool.push(...collectedTypedDefinitions); | ||
visitedDefinitions[defName] = true; | ||
visitedDefinitions['name' in newDefinition ? newDefinition.name.value : 'schema'] = true; | ||
} | ||
@@ -526,20 +525,20 @@ return uniqBy(definitionPool, 'name.value'); | ||
let newTypeDefinitions = []; | ||
if (newDefinition.kind !== Kind.DIRECTIVE_DEFINITION) { | ||
if (newDefinition.kind !== 'DirectiveDefinition') { | ||
newDefinition.directives.forEach(collectDirective); | ||
} | ||
if (newDefinition.kind === Kind.ENUM_TYPE_DEFINITION) { | ||
newDefinition.values.forEach((value) => value.directives.forEach(collectDirective)); | ||
if (newDefinition.kind === 'EnumTypeDefinition') { | ||
newDefinition.values.forEach(value => value.directives.forEach(collectDirective)); | ||
} | ||
if (newDefinition.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION) { | ||
if (newDefinition.kind === 'InputObjectTypeDefinition') { | ||
newDefinition.fields.forEach(collectNode); | ||
} | ||
if (newDefinition.kind === Kind.INTERFACE_TYPE_DEFINITION) { | ||
if (newDefinition.kind === 'InterfaceTypeDefinition') { | ||
const interfaceName = newDefinition.name.value; | ||
newDefinition.fields.forEach(collectNode); | ||
const interfaceImplementations = allDefinitions.filter((d) => d.kind === Kind.OBJECT_TYPE_DEFINITION && d.interfaces.some((i) => i.name.value === interfaceName)); | ||
const interfaceImplementations = allDefinitions.filter(d => d.kind === 'ObjectTypeDefinition' && d.interfaces.some(i => i.name.value === interfaceName)); | ||
newTypeDefinitions.push(...interfaceImplementations); | ||
} | ||
if (newDefinition.kind === Kind.UNION_TYPE_DEFINITION) { | ||
newDefinition.types.forEach((type) => { | ||
if (!definitionPool.some((d) => 'name' in d && d.name.value === type.name.value)) { | ||
if (newDefinition.kind === 'UnionTypeDefinition') { | ||
newDefinition.types.forEach(type => { | ||
if (!definitionPool.some(d => 'name' in d && d.name.value === type.name.value)) { | ||
const typeName = type.name.value; | ||
@@ -554,6 +553,6 @@ const typeMatch = schemaMap[typeName]; | ||
} | ||
if (newDefinition.kind === Kind.OBJECT_TYPE_DEFINITION) { | ||
if (newDefinition.kind === 'ObjectTypeDefinition') { | ||
// collect missing interfaces | ||
newDefinition.interfaces.forEach((int) => { | ||
if (!definitionPool.some((d) => 'name' in d && d.name.value === int.name.value)) { | ||
newDefinition.interfaces.forEach(int => { | ||
if (!definitionPool.some(d => 'name' in d && d.name.value === int.name.value)) { | ||
const interfaceName = int.name.value; | ||
@@ -568,3 +567,3 @@ const interfaceMatch = schemaMap[interfaceName]; | ||
// iterate over all fields | ||
newDefinition.fields.forEach((field) => { | ||
newDefinition.fields.forEach(field => { | ||
collectNode(field); | ||
@@ -575,5 +574,5 @@ // collect missing argument input types | ||
} | ||
if (newDefinition.kind === Kind.SCHEMA_DEFINITION) { | ||
newDefinition.operationTypes.forEach((operationType) => { | ||
if (!definitionPool.some((d) => 'name' in d && d.name.value === operationType.type.name.value)) { | ||
if (newDefinition.kind === 'SchemaDefinition') { | ||
newDefinition.operationTypes.forEach(operationType => { | ||
if (!definitionPool.some(d => 'name' in d && d.name.value === operationType.type.name.value)) { | ||
const typeName = operationType.type.name.value; | ||
@@ -599,3 +598,3 @@ const typeMatch = schemaMap[typeName]; | ||
const fragmentName = node.name.value; | ||
if (!definitionPool.some((d) => 'name' in d && d.name.value === fragmentName)) { | ||
if (!definitionPool.some(d => 'name' in d && d.name.value === fragmentName)) { | ||
const fragmentMatch = schemaMap[fragmentName]; | ||
@@ -621,3 +620,3 @@ if (!fragmentMatch) { | ||
// collect missing argument input types | ||
if (!definitionPool.some((d) => 'name' in d && d.name.value === nodeTypeName) && | ||
if (!definitionPool.some(d => 'name' in d && d.name.value === nodeTypeName) && | ||
!includes(builtinTypes, nodeTypeName)) { | ||
@@ -634,3 +633,3 @@ const argTypeMatch = schemaMap[nodeTypeName]; | ||
const directiveName = directive.name.value; | ||
if (!definitionPool.some((d) => 'name' in d && d.name.value === directiveName) && | ||
if (!definitionPool.some(d => 'name' in d && d.name.value === directiveName) && | ||
!includes(builtinDirectives, directiveName)) { | ||
@@ -653,3 +652,3 @@ const directive = schemaMap[directiveName]; | ||
function getNamedType(type) { | ||
if (type.kind === Kind.NAMED_TYPE) { | ||
if (type.kind === 'NamedType') { | ||
return type; | ||
@@ -660,2 +659,3 @@ } | ||
const rootFields = ['Query', 'Mutation', 'Subscription']; | ||
const gqlExt = /\.g(raph)?ql(s)?$/; | ||
@@ -681,3 +681,3 @@ function isGraphQLFile(f) { | ||
// Extract imported types | ||
const imports = wildcard === '*' ? ['*'] : importsString.split(',').map((d) => d.trim()); | ||
const imports = wildcard === '*' ? ['*'] : importsString.split(',').map(d => d.trim()); | ||
// Return information about the import line | ||
@@ -707,5 +707,5 @@ return { imports, from }; | ||
.split('\n') | ||
.map((l) => l.trim()) | ||
.filter((l) => l.startsWith('# import ') || l.startsWith('#import ')) | ||
.map((l) => l.replace('#', '').trim()) | ||
.map(l => l.trim()) | ||
.filter(l => l.startsWith('# import ') || l.startsWith('#import ')) | ||
.map(l => l.replace('#', '').trim()) | ||
.map(parseImportLine); | ||
@@ -732,3 +732,3 @@ } | ||
* | ||
* @param documentSource File path to the initial schema file | ||
* @param filePath File path to the initial schema file | ||
* @returns Single bundled schema with all imported types | ||
@@ -746,2 +746,3 @@ */ | ||
} | ||
// | ||
function process$1({ typeDefinitions, options, allDefinitions, }) { | ||
@@ -765,3 +766,3 @@ // Post processing of the final schema (missing types, unused types, etc.) | ||
else { | ||
const existingType = mergedFirstTypes.find((t) => t.name.value === type.name.value); | ||
const existingType = mergedFirstTypes.find(t => t.name.value === type.name.value); | ||
if ('fields' in existingType) { | ||
@@ -803,4 +804,4 @@ existingType.fields = uniqBy(existingType.fields.concat(type.fields), 'name.value'); | ||
.split('\n') | ||
.map((l) => l.trim()) | ||
.filter((l) => !(l.length === 0 || l.startsWith('#'))).length === 0); | ||
.map(l => l.trim()) | ||
.filter(l => !(l.length === 0 || l.startsWith('#'))).length === 0); | ||
} | ||
@@ -880,3 +881,3 @@ /** | ||
// Process each file (recursively) | ||
rawModules.forEach((module) => { | ||
rawModules.forEach(module => { | ||
// If it was not yet processed (in case of circular dependencies) | ||
@@ -907,3 +908,3 @@ const filepath = resolveModuleFilePath(source.location, module.from, options); | ||
const processedFile = options.processedFiles.get(filepath); | ||
if (!processedFile || !processedFile.find((rModule) => isEqual(rModule, module))) { | ||
if (!processedFile || !processedFile.find(rModule => isEqual(rModule, module))) { | ||
// Mark this specific import line as processed for this file (for cicular dependency cases) | ||
@@ -928,4 +929,4 @@ options.processedFiles.set(filepath, processedFile ? processedFile.concat(module) : [module]); | ||
if (imports.length === 1 && imports[0] === '*' && allDefinitions.length > 1) { | ||
const previousTypeDefinitions = keyBy(flatten(allDefinitions.slice(0, allDefinitions.length - 1)).filter((def) => 'name' in def), (def) => 'name' in def && def.name.value); | ||
return typeDefinitions.filter((typeDef) => typeDef.kind === 'ObjectTypeDefinition' && previousTypeDefinitions[typeDef.name.value]); | ||
const previousTypeDefinitions = keyBy(flatten(allDefinitions.slice(0, allDefinitions.length - 1)).filter(def => 'name' in def && !rootFields.includes(def.name.value)), def => 'name' in def && def.name.value); | ||
return typeDefinitions.filter(typeDef => typeDef.kind === 'ObjectTypeDefinition' && previousTypeDefinitions[typeDef.name.value]); | ||
} | ||
@@ -935,9 +936,9 @@ return filteredDefinitions; | ||
else { | ||
const importedTypes = imports.map((i) => i.split('.')[0]); | ||
const result = filteredDefinitions.filter((d) => 'name' in d && importedTypes.includes(d.name.value)); | ||
const fieldImports = imports.filter((i) => i.split('.').length > 1); | ||
const groupedFieldImports = groupBy(fieldImports, (x) => x.split('.')[0]); | ||
const importedTypes = imports.map(i => i.split('.')[0]); | ||
const result = filteredDefinitions.filter(d => 'name' in d && importedTypes.includes(d.name.value)); | ||
const fieldImports = imports.filter(i => i.split('.').length > 1); | ||
const groupedFieldImports = groupBy(fieldImports, x => x.split('.')[0]); | ||
for (const rootType in groupedFieldImports) { | ||
const fields = groupedFieldImports[rootType].map((x) => x.split('.')[1]); | ||
const objectTypeDefinition = filteredDefinitions.find((def) => 'name' in def && def.name.value === rootType); | ||
const fields = groupedFieldImports[rootType].map(x => x.split('.')[1]); | ||
const objectTypeDefinition = filteredDefinitions.find(def => 'name' in def && def.name.value === rootType); | ||
if (objectTypeDefinition && 'fields' in objectTypeDefinition && !fields.includes('*')) { | ||
@@ -944,0 +945,0 @@ objectTypeDefinition.fields = objectTypeDefinition.fields.filter((f) => fields.includes(f.name.value) || fields.includes('*')); |
{ | ||
"name": "@graphql-toolkit/core", | ||
"version": "0.10.3-alpha-d33816a.8+d33816a", | ||
"version": "0.10.3-alpha-e61b7c0.6+e61b7c0", | ||
"description": "A set of utils for faster development of GraphQL tools", | ||
@@ -18,4 +18,4 @@ "peerDependencies": { | ||
"dependencies": { | ||
"@graphql-toolkit/common": "0.10.3-alpha-d33816a.8+d33816a", | ||
"@graphql-toolkit/schema-merging": "0.10.3-alpha-d33816a.8+d33816a", | ||
"@graphql-toolkit/common": "0.10.3-alpha-e61b7c0.6+e61b7c0", | ||
"@graphql-toolkit/schema-merging": "0.10.3-alpha-e61b7c0.6+e61b7c0", | ||
"aggregate-error": "3.0.1", | ||
@@ -22,0 +22,0 @@ "globby": "11.0.0", |
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
2538
103023