graphql-import
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -58,3 +58,3 @@ "use strict"; | ||
var sdl = read(schema, schemas) || schema; | ||
var document = graphql_1.parse(sdl, { noLocation: true }); | ||
var document = getDocumentFromSDL(sdl); | ||
// Recursively process the imports, starting by importing all types from the initial schema | ||
@@ -92,2 +92,33 @@ var _a = collectDefinitions(['*'], sdl, schema, schemas), allDefinitions = _a.allDefinitions, typeDefinitions = _a.typeDefinitions; | ||
/** | ||
* Parses a schema into a graphql DocumentNode. | ||
* If the schema is empty a DocumentNode with empty definitions will be created. | ||
* | ||
* @param sdl Schema to parse | ||
* @returns A graphql DocumentNode with definitions of the parsed sdl. | ||
*/ | ||
function getDocumentFromSDL(sdl) { | ||
if (isEmptySDL(sdl)) { | ||
return { | ||
kind: graphql_1.Kind.DOCUMENT, | ||
definitions: [], | ||
}; | ||
} | ||
else { | ||
return graphql_1.parse(sdl, { noLocation: true }); | ||
} | ||
} | ||
/** | ||
* Check if a schema contains any type definitions at all. | ||
* | ||
* @param sdl Schema to parse | ||
* @returns True if SDL only contains comments and/or whitespaces | ||
*/ | ||
function isEmptySDL(sdl) { | ||
return sdl | ||
.split('\n') | ||
.map(function (l) { return l.trim(); }) | ||
.filter(function (l) { return !(l.length === 0 || l.startsWith('#')); }) | ||
.length === 0; | ||
} | ||
/** | ||
* Recursively process all schema files. Keeps track of both the filtered | ||
@@ -112,3 +143,3 @@ * type definitions, and all type definitions, because they might be needed | ||
// Get TypeDefinitionNodes from current schema | ||
var document = graphql_1.parse(sdl); | ||
var document = getDocumentFromSDL(sdl); | ||
// Add all definitions to running total | ||
@@ -115,0 +146,0 @@ allDefinitions.push(filterTypeDefinitions(document.definitions)); |
@@ -48,2 +48,6 @@ "use strict"; | ||
}); | ||
ava_1.default('importSchema: imports only', function (t) { | ||
var expectedSDL = "type Query {\n first: String\n second: Float\n third: String\n}\n"; | ||
t.is(_1.importSchema('fixtures/imports-only/all.graphql'), expectedSDL); | ||
}); | ||
ava_1.default('importSchema: field types', function (t) { | ||
@@ -50,0 +54,0 @@ var expectedSDL = "type A {\n first: String\n second: Float\n b: B\n}\n\ntype B {\n c: C\n hello: String!\n}\n\ntype C {\n id: ID!\n}\n"; |
{ | ||
"name": "graphql-import", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"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
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
49746
566