WIP - add extractor, generate snippet_data

This commit is contained in:
Stefan Fejes
2019-08-20 15:52:05 +02:00
parent 88084d3d30
commit cc8f1d8a7a
37396 changed files with 4588842 additions and 133 deletions

15
node_modules/graphql-import/dist/definition.d.ts generated vendored Normal file
View File

@ -0,0 +1,15 @@
import { TypeDefinitionNode, DirectiveDefinitionNode } from 'graphql';
export declare type ValidDefinitionNode = DirectiveDefinitionNode | TypeDefinitionNode;
export interface DefinitionMap {
[key: string]: ValidDefinitionNode;
}
/**
* Post processing of all imported type definitions. Loops over each of the
* imported type definitions, and processes it using collectNewTypeDefinitions.
*
* @param allDefinitions All definitions from all schemas
* @param definitionPool Current definitions (from first schema)
* @param newTypeDefinitions All imported definitions
* @returns Final collection of type definitions for the resulting schema
*/
export declare function completeDefinitionPool(allDefinitions: ValidDefinitionNode[], definitionPool: ValidDefinitionNode[], newTypeDefinitions: ValidDefinitionNode[]): ValidDefinitionNode[];

134
node_modules/graphql-import/dist/definition.js generated vendored Normal file
View File

@ -0,0 +1,134 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var lodash_1 = require("lodash");
var builtinTypes = ['String', 'Float', 'Int', 'Boolean', 'ID'];
var builtinDirectives = ['deprecated', 'skip', 'include'];
/**
* Post processing of all imported type definitions. Loops over each of the
* imported type definitions, and processes it using collectNewTypeDefinitions.
*
* @param allDefinitions All definitions from all schemas
* @param definitionPool Current definitions (from first schema)
* @param newTypeDefinitions All imported definitions
* @returns Final collection of type definitions for the resulting schema
*/
function completeDefinitionPool(allDefinitions, definitionPool, newTypeDefinitions) {
var visitedDefinitions = {};
while (newTypeDefinitions.length > 0) {
var schemaMap = lodash_1.keyBy(allDefinitions, function (d) { return d.name.value; });
var newDefinition = newTypeDefinitions.shift();
if (visitedDefinitions[newDefinition.name.value]) {
continue;
}
var collectedTypedDefinitions = collectNewTypeDefinitions(allDefinitions, definitionPool, newDefinition, schemaMap);
newTypeDefinitions.push.apply(newTypeDefinitions, collectedTypedDefinitions);
definitionPool.push.apply(definitionPool, collectedTypedDefinitions);
visitedDefinitions[newDefinition.name.value] = true;
}
return lodash_1.uniqBy(definitionPool, 'name.value');
}
exports.completeDefinitionPool = completeDefinitionPool;
/**
* Processes a single type definition, and performs a number of checks:
* - Add missing interface implementations
* - Add missing referenced types
* - Remove unused type definitions
*
* @param allDefinitions All definitions from all schemas
* (only used to find missing interface implementations)
* @param definitionPool Resulting definitions
* @param newDefinition All imported definitions
* @param schemaMap Map of all definitions for easy lookup
* @returns All relevant type definitions to add to the final schema
*/
function collectNewTypeDefinitions(allDefinitions, definitionPool, newDefinition, schemaMap) {
var newTypeDefinitions = [];
if (newDefinition.kind !== 'DirectiveDefinition') {
newDefinition.directives.forEach(collectDirective);
}
if (newDefinition.kind === 'InputObjectTypeDefinition') {
newDefinition.fields.forEach(collectNode);
}
if (newDefinition.kind === 'InterfaceTypeDefinition') {
var interfaceName_1 = newDefinition.name.value;
newDefinition.fields.forEach(collectNode);
var interfaceImplementations = allDefinitions.filter(function (d) {
return d.kind === 'ObjectTypeDefinition' &&
d.interfaces.some(function (i) { return i.name.value === interfaceName_1; });
});
newTypeDefinitions.push.apply(newTypeDefinitions, interfaceImplementations);
}
if (newDefinition.kind === 'UnionTypeDefinition') {
newDefinition.types.forEach(function (type) {
if (!definitionPool.some(function (d) { return d.name.value === type.name.value; })) {
var typeName = type.name.value;
var typeMatch = schemaMap[typeName];
if (!typeMatch) {
throw new Error("Couldn't find type " + typeName + " in any of the schemas.");
}
newTypeDefinitions.push(schemaMap[type.name.value]);
}
});
}
if (newDefinition.kind === 'ObjectTypeDefinition') {
// collect missing interfaces
newDefinition.interfaces.forEach(function (int) {
if (!definitionPool.some(function (d) { return d.name.value === int.name.value; })) {
var interfaceName = int.name.value;
var interfaceMatch = schemaMap[interfaceName];
if (!interfaceMatch) {
throw new Error("Couldn't find interface " + interfaceName + " in any of the schemas.");
}
newTypeDefinitions.push(schemaMap[int.name.value]);
}
});
// iterate over all fields
newDefinition.fields.forEach(function (field) {
collectNode(field);
// collect missing argument input types
field.arguments.forEach(collectNode);
});
}
return newTypeDefinitions;
function collectNode(node) {
var nodeType = getNamedType(node.type);
var nodeTypeName = nodeType.name.value;
// collect missing argument input types
if (!definitionPool.some(function (d) { return d.name.value === nodeTypeName; }) &&
!lodash_1.includes(builtinTypes, nodeTypeName)) {
var argTypeMatch = schemaMap[nodeTypeName];
if (!argTypeMatch) {
throw new Error("Field " + node.name.value + ": Couldn't find type " + nodeTypeName + " in any of the schemas.");
}
newTypeDefinitions.push(argTypeMatch);
}
node.directives.forEach(collectDirective);
}
function collectDirective(directive) {
var directiveName = directive.name.value;
if (!definitionPool.some(function (d) { return d.name.value === directiveName; }) &&
!lodash_1.includes(builtinDirectives, directiveName)) {
var directive_1 = schemaMap[directiveName];
if (!directive_1) {
throw new Error("Directive " + directiveName + ": Couldn't find type " + directiveName + " in any of the schemas.");
}
directive_1.arguments.forEach(collectNode);
newTypeDefinitions.push(directive_1);
}
}
}
/**
* Nested visitor for a type node to get to the final NamedType
*
* @param {TypeNode} type Type node to get NamedTypeNode for
* @returns {NamedTypeNode} The found NamedTypeNode
*/
function getNamedType(type) {
if (type.kind === 'NamedType') {
return type;
}
else {
return getNamedType(type.type);
}
}
//# sourceMappingURL=definition.js.map

1
node_modules/graphql-import/dist/definition.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"definition.js","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":";;AAAA,iCAAgD;AAchD,IAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;AAEhE,IAAM,iBAAiB,GAAG,CAAC,YAAY,EAAE,MAAM,EAAC,SAAS,CAAC,CAAA;AAU1D;;;;;;;;GAQG;AACH,SAAgB,sBAAsB,CACpC,cAAqC,EACrC,cAAqC,EACrC,kBAAyC;IAEzC,IAAM,kBAAkB,GAAgC,EAAE,CAAA;IAC1D,OAAO,kBAAkB,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AED,SAAS,gBAAgB,CAAC,SAAwB;QAChD,IAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAA;QAC1C,IACE,CAAC,cAAc,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,CAAC,KAAK,KAAK,aAAa,EAA9B,CAA8B,CAAC;YACzD,CAAC,iBAAQ,CAAC,iBAAiB,EAAE,aAAa,CAAC,EAC3C;YACA,IAAM,WAAS,GAAG,SAAS,CAAC,aAAa,CAA4B,CAAA;YACrE,IAAI,CAAC,WAAS,EAAE;gBACd,MAAM,IAAI,KAAK,CACb,eAAa,aAAa,6BACxB,aAAa,4BACU,CAC1B,CAAA;aACF;YACD,WAAS,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;YAExC,kBAAkB,CAAC,IAAI,CAAC,WAAS,CAAC,CAAA;SACnC;IACH,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,IAAc;IAClC,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,EAAE;QAC7B,OAAO,IAAI,CAAA;KACZ;SAAM;QACL,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;KAC/B;AACH,CAAC"}

31
node_modules/graphql-import/dist/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,31 @@
/**
* Describes the information from a single import line
*
*/
export interface RawModule {
imports: string[];
from: string;
}
/**
* Parse a single import line and extract imported types and schema filename
*
* @param importLine Import line
* @returns Processed import line
*/
export declare function parseImportLine(importLine: string): RawModule;
/**
* Parse a schema and analyze all import lines
*
* @param sdl Schema to parse
* @returns Array with collection of imports per import line (file)
*/
export declare function parseSDL(sdl: string): RawModule[];
/**
* Main entry point. Recursively process all import statement in a schema
*
* @param filePath File path to the initial schema file
* @returns Single bundled schema with all imported types
*/
export declare function importSchema(schema: string, schemas?: {
[key: string]: string;
}): string;

258
node_modules/graphql-import/dist/index.js generated vendored Normal file
View File

@ -0,0 +1,258 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = require("fs");
var graphql_1 = require("graphql");
var lodash_1 = require("lodash");
var path = require("path");
var resolveFrom = require("resolve-from");
var definition_1 = require("./definition");
var rootFields = ['Query', 'Mutation', 'Subscription'];
var read = function (schema, schemas) {
if (isFile(schema)) {
return fs.readFileSync(schema, { encoding: 'utf8' });
}
return schemas ? schemas[schema] : schema;
};
var isFile = function (f) { return f.endsWith('.graphql'); };
/**
* Parse a single import line and extract imported types and schema filename
*
* @param importLine Import line
* @returns Processed import line
*/
function parseImportLine(importLine) {
// Apply regex to import line
var matches = importLine.match(/^import (\*|(.*)) from ('|")(.*)('|");?$/);
if (!matches || matches.length !== 6 || !matches[4]) {
throw new Error("Too few regex matches: " + matches);
}
// Extract matches into named variables
var wildcard = matches[1], importsString = matches[2], from = matches[4];
// Extract imported types
var imports = wildcard === '*' ? ['*'] : importsString.split(',').map(function (d) { return d.trim(); });
// Return information about the import line
return { imports: imports, from: from };
}
exports.parseImportLine = parseImportLine;
/**
* Parse a schema and analyze all import lines
*
* @param sdl Schema to parse
* @returns Array with collection of imports per import line (file)
*/
function parseSDL(sdl) {
return sdl
.split('\n')
.map(function (l) { return l.trim(); })
.filter(function (l) { return l.startsWith('# import ') || l.startsWith('#import '); })
.map(function (l) { return l.replace('#', '').trim(); })
.map(parseImportLine);
}
exports.parseSDL = parseSDL;
/**
* Main entry point. Recursively process all import statement in a schema
*
* @param filePath File path to the initial schema file
* @returns Single bundled schema with all imported types
*/
function importSchema(schema, schemas) {
var sdl = read(schema, schemas) || schema;
var document = getDocumentFromSDL(sdl);
// Recursively process the imports, starting by importing all types from the initial schema
var _a = collectDefinitions(['*'], sdl, schema, schemas), allDefinitions = _a.allDefinitions, typeDefinitions = _a.typeDefinitions;
// Post processing of the final schema (missing types, unused types, etc.)
// Query, Mutation and Subscription should be merged
// And should always be in the first set, to make sure they
// are not filtered out.
var firstTypes = lodash_1.flatten(typeDefinitions).filter(function (d) {
return lodash_1.includes(rootFields, d.name.value);
});
var otherFirstTypes = typeDefinitions[0].filter(function (d) { return !lodash_1.includes(rootFields, d.name.value); });
var firstSet = firstTypes.concat(otherFirstTypes);
var processedTypeNames = [];
var mergedFirstTypes = [];
var _loop_1 = function (type) {
if (!lodash_1.includes(processedTypeNames, type.name.value)) {
processedTypeNames.push(type.name.value);
mergedFirstTypes.push(type);
}
else {
var existingType = mergedFirstTypes.find(function (t) { return t.name.value === type.name.value; });
existingType.fields = existingType.fields.concat(type.fields);
}
};
for (var _i = 0, firstSet_1 = firstSet; _i < firstSet_1.length; _i++) {
var type = firstSet_1[_i];
_loop_1(type);
}
document = __assign({}, document, { definitions: definition_1.completeDefinitionPool(lodash_1.flatten(allDefinitions), firstSet, lodash_1.flatten(typeDefinitions)) });
// Return the schema as string
return graphql_1.print(document);
}
exports.importSchema = importSchema;
/**
* 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);
}
/**
* Resolve the path of an import.
* First it will try to find a file relative from the file the import is in, if that fails it will try to resolve it as a module so imports from packages work correctly.
*
* @param filePath Path the import was made from
* @param importFrom Path given for the import
* @returns Full resolved path to a file
*/
function resolveModuleFilePath(filePath, importFrom) {
var dirname = path.dirname(filePath);
if (isFile(filePath) && isFile(importFrom)) {
try {
return fs.realpathSync(path.join(dirname, importFrom));
}
catch (e) {
if (e.code === 'ENOENT') {
return resolveFrom(dirname, importFrom);
}
}
}
return importFrom;
}
/**
* Recursively process all schema files. Keeps track of both the filtered
* type definitions, and all type definitions, because they might be needed
* in post-processing (to add missing types)
*
* @param imports Types specified in the import statement
* @param sdl Current schema
* @param filePath File location for current schema
* @param Tracking of processed schemas (for circular dependencies)
* @param Tracking of imported type definitions per schema
* @param Tracking of all type definitions per schema
* @returns Both the collection of all type definitions, and the collection of imported type definitions
*/
function collectDefinitions(imports, sdl, filePath, schemas, processedFiles, typeDefinitions, allDefinitions) {
if (processedFiles === void 0) { processedFiles = new Map(); }
if (typeDefinitions === void 0) { typeDefinitions = []; }
if (allDefinitions === void 0) { allDefinitions = []; }
var key = isFile(filePath) ? path.resolve(filePath) : filePath;
// Get TypeDefinitionNodes from current schema
var document = getDocumentFromSDL(sdl);
// Add all definitions to running total
allDefinitions.push(filterTypeDefinitions(document.definitions));
// Filter TypeDefinitionNodes by type and defined imports
var currentTypeDefinitions = filterImportedDefinitions(imports, document.definitions, allDefinitions);
// Add typedefinitions to running total
typeDefinitions.push(currentTypeDefinitions);
// Read imports from current file
var rawModules = parseSDL(sdl);
// Process each file (recursively)
rawModules.forEach(function (m) {
// If it was not yet processed (in case of circular dependencies)
var moduleFilePath = resolveModuleFilePath(filePath, m.from);
var processedFile = processedFiles.get(key);
if (!processedFile || !processedFile.find(function (rModule) { return lodash_1.isEqual(rModule, m); })) {
// Mark this specific import line as processed for this file (for cicular dependency cases)
processedFiles.set(key, processedFile ? processedFile.concat(m) : [m]);
collectDefinitions(m.imports, read(moduleFilePath, schemas), moduleFilePath, schemas, processedFiles, typeDefinitions, allDefinitions);
}
});
// Return the maps of type definitions from each file
return { allDefinitions: allDefinitions, typeDefinitions: typeDefinitions };
}
/**
* Filter the types loaded from a schema, first by relevant types,
* then by the types specified in the import statement.
*
* @param imports Types specified in the import statement
* @param typeDefinitions All definitions from a schema
* @returns Filtered collection of type definitions
*/
function filterImportedDefinitions(imports, typeDefinitions, allDefinitions) {
// This should do something smart with fields
if (allDefinitions === void 0) { allDefinitions = []; }
var filteredDefinitions = filterTypeDefinitions(typeDefinitions);
if (lodash_1.includes(imports, '*')) {
if (imports.length === 1 &&
imports[0] === '*' &&
allDefinitions.length > 1) {
var previousTypeDefinitions_1 = lodash_1.keyBy(lodash_1.flatten(allDefinitions.slice(0, allDefinitions.length - 1)).filter(function (def) { return !lodash_1.includes(rootFields, def.name.value); }), function (def) { return def.name.value; });
return typeDefinitions.filter(function (typeDef) {
return typeDef.kind === 'ObjectTypeDefinition' &&
previousTypeDefinitions_1[typeDef.name.value];
});
}
return filteredDefinitions;
}
else {
var result = filteredDefinitions.filter(function (d) {
return lodash_1.includes(imports.map(function (i) { return i.split('.')[0]; }), d.name.value);
});
var fieldImports = imports.filter(function (i) { return i.split('.').length > 1; });
var groupedFieldImports = lodash_1.groupBy(fieldImports, function (x) { return x.split('.')[0]; });
var _loop_2 = function (rootType) {
var fields = groupedFieldImports[rootType].map(function (x) { return x.split('.')[1]; });
filteredDefinitions.find(function (def) { return def.name.value === rootType; }).fields = filteredDefinitions.find(function (def) { return def.name.value === rootType; }).fields.filter(function (f) { return lodash_1.includes(fields, f.name.value) || lodash_1.includes(fields, '*'); });
};
for (var rootType in groupedFieldImports) {
_loop_2(rootType);
}
return result;
}
}
/**
* Filter relevant definitions from schema
*
* @param definitions All definitions from a schema
* @returns Relevant type definitions
*/
function filterTypeDefinitions(definitions) {
var validKinds = [
'DirectiveDefinition',
'ScalarTypeDefinition',
'ObjectTypeDefinition',
'InterfaceTypeDefinition',
'EnumTypeDefinition',
'UnionTypeDefinition',
'InputObjectTypeDefinition',
];
return definitions
.filter(function (d) { return lodash_1.includes(validKinds, d.kind); })
.map(function (d) { return d; });
}
//# sourceMappingURL=index.js.map

1
node_modules/graphql-import/dist/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

1
node_modules/graphql-import/dist/index.test.d.ts generated vendored Normal file
View File

@ -0,0 +1 @@
export {};

239
node_modules/graphql-import/dist/index.test.js generated vendored Normal file
View File

@ -0,0 +1,239 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ava_1 = require("ava");
var fs = require("fs");
var _1 = require(".");
ava_1.default('parseImportLine: parse single import', function (t) {
t.deepEqual(_1.parseImportLine("import A from \"schema.graphql\""), {
imports: ['A'],
from: 'schema.graphql',
});
});
ava_1.default('parseImportLine: optional semicolon', function (t) {
t.deepEqual(_1.parseImportLine("import A from \"schema.graphql\";"), {
imports: ['A'],
from: 'schema.graphql',
});
});
ava_1.default('parseImportLine: invalid', function (t) {
t.throws(function () { return _1.parseImportLine("import from \"schema.graphql\""); }, Error);
});
ava_1.default('parseImportLine: invalid 2', function (t) {
t.throws(function () { return _1.parseImportLine("import A from \"\""); }, Error);
});
ava_1.default('parseImportLine: parse multi import', function (t) {
t.deepEqual(_1.parseImportLine("import A, B from \"schema.graphql\""), {
imports: ['A', 'B'],
from: 'schema.graphql',
});
});
ava_1.default('parseImportLine: parse multi import (weird spacing)', function (t) {
t.deepEqual(_1.parseImportLine("import A ,B from \"schema.graphql\""), {
imports: ['A', 'B'],
from: 'schema.graphql',
});
});
ava_1.default('parseImportLine: different path', function (t) {
t.deepEqual(_1.parseImportLine("import A from \"../new/schema.graphql\""), {
imports: ['A'],
from: '../new/schema.graphql',
});
});
ava_1.default('parseImportLine: module in node_modules', function (t) {
t.deepEqual(_1.parseImportLine("import A from \"module-name\""), {
imports: ['A'],
from: 'module-name',
});
});
ava_1.default('parseSDL: non-import comment', function (t) {
t.deepEqual(_1.parseSDL("#importent: comment"), []);
});
ava_1.default('parse: multi line import', function (t) {
var sdl = "# import A from \"a.graphql\"\n# import * from \"b.graphql\"\n ";
t.deepEqual(_1.parseSDL(sdl), [
{
imports: ['A'],
from: 'a.graphql',
},
{
imports: ['*'],
from: 'b.graphql',
},
]);
});
ava_1.default('Module in node_modules', function (t) {
var b = "# import lower from './lower.graphql'\ntype B {\n id: ID!\n nickname: String! @lower\n}\n";
var lower = "directive @lower on FIELD_DEFINITION\n";
var expectedSDL = "type A {\n id: ID!\n author: B!\n}\n\ntype B {\n id: ID!\n nickname: String! @lower\n}\n\ndirective @lower on FIELD_DEFINITION\n";
var moduleDir = 'node_modules/graphql-import-test';
if (!fs.existsSync(moduleDir)) {
fs.mkdirSync(moduleDir);
}
fs.writeFileSync(moduleDir + '/b.graphql', b);
fs.writeFileSync(moduleDir + '/lower.graphql', lower);
t.is(_1.importSchema('fixtures/import-module/a.graphql'), expectedSDL);
});
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: import duplicate', function (t) {
var expectedSDL = "type Query {\n first: String\n second: Float\n third: String\n}\n";
t.is(_1.importSchema('fixtures/import-duplicate/all.graphql'), expectedSDL);
});
ava_1.default('importSchema: import nested', function (t) {
var expectedSDL = "type Query {\n first: String\n second: Float\n third: String\n}\n";
t.is(_1.importSchema('fixtures/import-nested/all.graphql'), expectedSDL);
});
ava_1.default('importSchema: field types', function (t) {
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";
t.is(_1.importSchema('fixtures/field-types/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: enums', function (t) {
var expectedSDL = "type A {\n first: String\n second: Float\n b: B\n}\n\nenum B {\n B1\n B2\n B3\n}\n";
t.is(_1.importSchema('fixtures/enums/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: import all', function (t) {
var expectedSDL = "type A {\n first: String\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);
});
ava_1.default('importSchema: import all from objects', function (t) {
var schemaC = "\n type C1 {\n id: ID!\n }\n\n type C2 {\n id: ID!\n }\n\n type C3 {\n id: ID!\n }";
var schemaB = "\n # import * from 'schemaC'\n\n type B {\n hello: String!\n c1: C1\n c2: C2\n }";
var schemaA = "\n # import B from 'schemaB'\n\n type A {\n # test 1\n first: String\n second: Float\n b: B\n }";
var schemas = {
schemaA: schemaA,
schemaB: schemaB,
schemaC: schemaC,
};
var expectedSDL = "type A {\n first: String\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(schemaA, schemas), expectedSDL);
});
ava_1.default("importSchema: single object schema", function (t) {
var schemaA = "\n type A {\n field: String\n }";
var expectedSDL = "type A {\n field: String\n}\n";
t.is(_1.importSchema(schemaA), expectedSDL);
});
ava_1.default("importSchema: import all mix 'n match", function (t) {
var schemaB = "\n # import C1, C2 from 'fixtures/import-all/c.graphql'\n\n type B {\n hello: String!\n c1: C1\n c2: C2\n }";
var schemaA = "\n # import * from \"schemaB\"\n\n type A {\n # test 1\n first: String\n second: Float\n b: B\n }";
var schemas = {
schemaB: schemaB,
};
var expectedSDL = "type A {\n first: String\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(schemaA, schemas), expectedSDL);
});
ava_1.default("importSchema: import all mix 'n match 2", function (t) {
var schemaA = "\n # import * from \"fixtures/import-all/b.graphql\"\n\n type A {\n # test 1\n first: String\n second: Float\n b: B\n }";
var expectedSDL = "type A {\n first: String\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(schemaA), expectedSDL);
});
ava_1.default("importSchema: import all - exclude Query/Mutation/Subscription type", function (t) {
var schemaC = "\n type C1 {\n id: ID!\n }\n\n type C2 {\n id: ID!\n }\n\n type C3 {\n id: ID!\n }\n\n type Query {\n hello: String!\n }\n\n type Mutation {\n hello: String!\n }\n\n type Subscription {\n hello: String!\n }\n ";
var schemaB = "\n # import * from 'schemaC'\n\n type B {\n hello: String!\n c1: C1\n c2: C2\n }";
var schemaA = "\n # import B from 'schemaB'\n\n type Query {\n greet: String!\n }\n\n type A {\n # test 1\n first: String\n second: Float\n b: B\n }";
var schemas = {
schemaA: schemaA,
schemaB: schemaB,
schemaC: schemaC,
};
var expectedSDL = "type Query {\n greet: String!\n}\n\ntype A {\n first: String\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(schemaA, schemas), expectedSDL);
});
ava_1.default('importSchema: scalar', function (t) {
var expectedSDL = "type A {\n b: B\n}\n\nscalar B\n";
t.is(_1.importSchema('fixtures/scalar/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: directive', function (t) {
var expectedSDL = "type A {\n first: String @upper\n second: String @withB @deprecated\n}\n\ndirective @upper on FIELD_DEFINITION\n\nscalar B\n\ndirective @withB(argB: B) on FIELD_DEFINITION\n";
t.is(_1.importSchema('fixtures/directive/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: interfaces', function (t) {
var expectedSDL = "type A implements B {\n first: String\n second: Float\n}\n\ninterface B {\n second: Float\n c: [C!]!\n}\n\ntype C {\n c: ID!\n}\n";
t.is(_1.importSchema('fixtures/interfaces/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: interfaces-many', function (t) {
var expectedSDL = "type A implements B {\n first: String\n second: Float\n}\n\ninterface B {\n second: Float\n c: [C!]!\n}\n\ntype C implements D1 & D2 {\n c: ID!\n}\n\ninterface D1 {\n d1: ID!\n}\n\ninterface D2 {\n d2: ID!\n}\n";
t.is(_1.importSchema('fixtures/interfaces-many/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: interfaces-implements', function (t) {
var expectedSDL = "type A implements B {\n id: ID!\n}\n\ninterface B {\n id: ID!\n}\n\ntype B1 implements B {\n id: ID!\n}\n";
t.is(_1.importSchema('fixtures/interfaces-implements/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: interfaces-implements-many', function (t) {
var expectedSDL = "type A implements B {\n id: ID!\n}\n\ninterface B {\n id: ID!\n}\n\ntype B1 implements B {\n id: ID!\n}\n\ntype B2 implements B {\n id: ID!\n}\n";
t.is(_1.importSchema('fixtures/interfaces-implements-many/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: input types', function (t) {
var expectedSDL = "type A {\n first(b: B): String\n second: Float\n}\n\ninput B {\n hello: [C!]!\n}\n\ninput C {\n id: ID!\n}\n";
t.is(_1.importSchema('fixtures/input-types/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: complex test', function (t) {
t.notThrows(function () {
_1.importSchema('fixtures/complex/a.graphql');
});
});
ava_1.default('circular imports', function (t) {
var expectedSDL = "type A {\n first: String\n second: Float\n b: B\n}\n\ntype B {\n hello: String!\n c1: C1\n c2: C2\n a: A\n}\n\ntype C1 {\n id: ID!\n}\n\ntype C2 {\n id: ID!\n}\n";
var actualSDL = _1.importSchema('fixtures/circular/a.graphql');
t.is(actualSDL, expectedSDL);
});
ava_1.default('related types', function (t) {
var expectedSDL = "type A {\n first: String\n second: Float\n b: B\n}\n\ntype B {\n hello: String!\n c1: C\n}\n\ntype C {\n field: String\n}\n";
var actualSDL = _1.importSchema('fixtures/related-types/a.graphql');
t.is(actualSDL, expectedSDL);
});
ava_1.default('relative paths', function (t) {
var expectedSDL = "type Query {\n feed: [Post!]!\n}\n\ntype Mutation {\n createDraft(title: String!, text: String): Post\n publish(id: ID!): Post\n}\n\ntype Post implements Node {\n id: ID!\n isPublished: Boolean!\n title: String!\n text: String!\n}\n\ninterface Node {\n id: ID!\n}\n";
var actualSDL = _1.importSchema('fixtures/relative-paths/src/schema.graphql');
t.is(actualSDL, expectedSDL);
});
ava_1.default('root field imports', function (t) {
var expectedSDL = "type Query {\n posts(filter: PostFilter): [Post]\n}\n\ntype Dummy {\n field: String\n}\n\ntype Post {\n field1: String\n}\n\ninput PostFilter {\n field3: Int\n}\n";
var actualSDL = _1.importSchema('fixtures/root-fields/a.graphql');
t.is(actualSDL, expectedSDL);
});
ava_1.default('merged root field imports', function (t) {
var expectedSDL = "type Query {\n helloA: String\n posts(filter: PostFilter): [Post]\n hello: String\n}\n\ntype Dummy {\n field: String\n}\n\ntype Post {\n field1: String\n}\n\ninput PostFilter {\n field3: Int\n}\n";
var actualSDL = _1.importSchema('fixtures/merged-root-fields/a.graphql');
t.is(actualSDL, expectedSDL);
});
ava_1.default('global schema modules', function (t) {
var shared = "\n type Shared {\n first: String\n }\n ";
var expectedSDL = "type A {\n first: String\n second: Shared\n}\n\ntype Shared {\n first: String\n}\n";
t.is(_1.importSchema('fixtures/global/a.graphql', { shared: shared }), expectedSDL);
});
ava_1.default('missing type on type', function (t) {
var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/a.graphql'); }, Error);
t.is(err.message, "Field test: Couldn't find type Post in any of the schemas.");
});
ava_1.default('missing type on interface', function (t) {
var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/b.graphql'); }, Error);
t.is(err.message, "Field test: Couldn't find type Post in any of the schemas.");
});
ava_1.default('missing type on input type', function (t) {
var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/c.graphql'); }, Error);
t.is(err.message, "Field post: Couldn't find type Post in any of the schemas.");
});
ava_1.default('missing interface type', function (t) {
var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/d.graphql'); }, Error);
t.is(err.message, "Couldn't find interface MyInterface in any of the schemas.");
});
ava_1.default('missing union type', function (t) {
var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/e.graphql'); }, Error);
t.is(err.message, "Couldn't find type C in any of the schemas.");
});
ava_1.default('missing type on input type', function (t) {
var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/f.graphql'); }, Error);
t.is(err.message, "Field myfield: Couldn't find type Post in any of the schemas.");
});
ava_1.default('missing type on directive', function (t) {
var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/g.graphql'); }, Error);
t.is(err.message, "Directive first: Couldn't find type first in any of the schemas.");
});
ava_1.default('import with collision', function (t) {
// Local type gets preference over imported type
var expectedSDL = "type User {\n id: ID!\n name: String!\n}\n";
t.is(_1.importSchema('fixtures/collision/a.graphql'), expectedSDL);
});
//# sourceMappingURL=index.test.js.map

1
node_modules/graphql-import/dist/index.test.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long