graphql-import
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -6,8 +6,15 @@ "use strict"; | ||
function completeDefinitionPool(allDefinitions, defintionPool, newTypeDefinitions, schemaPath) { | ||
var visitedDefinitions = {}; | ||
while (newTypeDefinitions.length > 0) { | ||
var schemaMap = lodash_1.keyBy(allDefinitions, function (d) { return d.name.value; }); | ||
var newDefinition = newTypeDefinitions.shift(); | ||
newTypeDefinitions.push.apply(newTypeDefinitions, collectNewTypeDefinitions(defintionPool, newDefinition, schemaMap, schemaPath)); | ||
if (visitedDefinitions[newDefinition.name.value]) { | ||
continue; | ||
} | ||
var collectedTypedDefinitions = collectNewTypeDefinitions(defintionPool, newDefinition, schemaMap, schemaPath); | ||
newTypeDefinitions.push.apply(newTypeDefinitions, collectedTypedDefinitions); | ||
defintionPool.push.apply(defintionPool, collectedTypedDefinitions); | ||
visitedDefinitions[newDefinition.name.value] = true; | ||
} | ||
return defintionPool; | ||
return lodash_1.uniqBy(defintionPool, 'name.value'); | ||
} | ||
@@ -14,0 +21,0 @@ exports.completeDefinitionPool = completeDefinitionPool; |
@@ -6,8 +6,5 @@ import { TypeDefinitionNode } from 'graphql'; | ||
} | ||
export interface Module { | ||
importedDefinitions: TypeDefinitionNode[]; | ||
} | ||
export declare function parseImportLine(importLine: string): RawModule; | ||
export declare function parseSDL(sdl: string): RawModule[]; | ||
export declare function importSchema(filePath: string): string; | ||
export declare function collectDefinitions(sdl: string, dirname: string): TypeDefinitionNode[]; | ||
export declare function collectDefinitions(imports: string[], sdl: string, filePath: string): TypeDefinitionNode[]; |
@@ -31,8 +31,9 @@ "use strict"; | ||
var document = graphql_1.parse(sdl); | ||
var allDefinitions = filterTypeDefinitions(document.definitions).concat(collectDefinitions(sdl, path.dirname(path.resolve(filePath)))); | ||
document.definitions = lodash_1.uniqBy(allDefinitions, 'name.value'); | ||
var allDefinitions = collectDefinitions(['*'], sdl, path.resolve(filePath)); | ||
document.definitions = allDefinitions; | ||
return graphql_1.print(document); | ||
} | ||
exports.importSchema = importSchema; | ||
function collectDefinitions(sdl, dirname) { | ||
function collectDefinitions(imports, sdl, filePath) { | ||
var dirname = path.dirname(filePath); | ||
var rawModules = parseSDL(sdl); | ||
@@ -42,8 +43,8 @@ var document = graphql_1.parse(sdl); | ||
var importedTypeDefinitions = lodash_1.flatten(rawModules.map(function (m) { | ||
var filePath = path.resolve(path.join(dirname, m.from)); | ||
var sdl = read(filePath); | ||
return collectDefinitions(sdl, path.dirname(filePath)); | ||
var moduleFilePath = path.resolve(path.join(dirname, m.from)); | ||
return collectDefinitions(m.imports, read(moduleFilePath), moduleFilePath); | ||
})); | ||
var typeDefinitions = currentTypeDefinitions.concat(importedTypeDefinitions); | ||
return lodash_1.flatten(typeDefinitions.concat(rawModules.map(function (m) { return importDefinitions(m.imports, importedTypeDefinitions, m.from); }))); | ||
var filteredTypeDefinitions = importDefinitions(imports, typeDefinitions, filePath); | ||
return definition_1.completeDefinitionPool(typeDefinitions, filteredTypeDefinitions.slice(0), filteredTypeDefinitions.slice(0), filePath); | ||
} | ||
@@ -59,3 +60,3 @@ exports.collectDefinitions = collectDefinitions; | ||
}); | ||
return definition_1.completeDefinitionPool(typeDefinitions, importedDefinitions, importedDefinitions, schemaPath); | ||
return definition_1.completeDefinitionPool(typeDefinitions, importedDefinitions.slice(0), importedDefinitions.slice(0), schemaPath); | ||
} | ||
@@ -62,0 +63,0 @@ } |
@@ -51,3 +51,3 @@ "use strict"; | ||
ava_1.default('importSchema: import all', function (t) { | ||
var expectedSDL = "type A {\n first: String @first\n second: Float\n b: B\n}\n\ntype B {\n hello: String!\n}\n\ntype C1 {\n id: ID!\n}\n\ntype C2 {\n id: ID!\n}\n"; | ||
var expectedSDL = "type A {\n first: String @first\n second: Float\n b: B\n}\n\ntype B {\n hello: String!\n c1: C1\n c2: C2\n}\n\ntype C1 {\n id: ID!\n}\n\ntype C2 {\n id: ID!\n}\n"; | ||
t.is(_1.importSchema('fixtures/import-all/a.graphql'), expectedSDL); | ||
@@ -63,2 +63,7 @@ }); | ||
}); | ||
ava_1.default('importSchema: complex test', function (t) { | ||
t.notThrows(function () { | ||
_1.importSchema('fixtures/complex/a.graphql'); | ||
}); | ||
}); | ||
//# sourceMappingURL=index.test.js.map |
{ | ||
"name": "graphql-import", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:graphcool/graphql-import.git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
23606
240