graphql-compose-modules
Advanced tools
Comparing version 1.0.0 to 1.0.1
/// <reference types="node" /> | ||
import { requireSchemaDirectory } from './requireSchemaDirectory'; | ||
import { requireAstToSchema } from './requireAstToSchema'; | ||
export declare function buildSchema(module: NodeModule): import("graphql").GraphQLSchema; | ||
export declare function loadSchemaComposer(module: NodeModule): import("graphql-compose").SchemaComposer<any>; | ||
import { requireSchemaDirectory, RequireOptions } from './requireSchemaDirectory'; | ||
import { requireAstToSchema, AstOptions } from './requireAstToSchema'; | ||
export interface BuildOptions extends RequireOptions, AstOptions { | ||
} | ||
export declare function buildSchema(module: NodeModule, opts?: BuildOptions): import("graphql").GraphQLSchema; | ||
export declare function loadSchemaComposer(module: NodeModule, opts: BuildOptions): import("graphql-compose").SchemaComposer<any>; | ||
export { requireSchemaDirectory, requireAstToSchema }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -7,9 +7,10 @@ "use strict"; | ||
exports.requireAstToSchema = requireAstToSchema_1.requireAstToSchema; | ||
function buildSchema(module) { | ||
return loadSchemaComposer(module).buildSchema(); | ||
function buildSchema(module, opts) { | ||
if (opts === void 0) { opts = {}; } | ||
return loadSchemaComposer(module, opts).buildSchema(); | ||
} | ||
exports.buildSchema = buildSchema; | ||
function loadSchemaComposer(module) { | ||
var ast = requireSchemaDirectory_1.requireSchemaDirectory(module); | ||
var sc = requireAstToSchema_1.requireAstToSchema(ast); | ||
function loadSchemaComposer(module, opts) { | ||
var ast = requireSchemaDirectory_1.requireSchemaDirectory(module, opts); | ||
var sc = requireAstToSchema_1.requireAstToSchema(ast, opts); | ||
return sc; | ||
@@ -16,0 +17,0 @@ } |
import { SchemaComposer } from 'graphql-compose'; | ||
import { RequireAstResult } from './requireSchemaDirectory'; | ||
export declare function requireAstToSchema<TContext = any>(ast: RequireAstResult, schemaComposer?: SchemaComposer<TContext>): SchemaComposer<TContext>; | ||
export interface AstOptions { | ||
schemaComposer?: SchemaComposer<any>; | ||
} | ||
export declare function requireAstToSchema<TContext = any>(ast: RequireAstResult, opts?: AstOptions): SchemaComposer<TContext>; | ||
//# sourceMappingURL=requireAstToSchema.d.ts.map |
@@ -24,4 +24,15 @@ "use strict"; | ||
var graphql_1 = require("graphql"); | ||
function requireAstToSchema(ast, schemaComposer) { | ||
var sc = schemaComposer || new graphql_compose_1.SchemaComposer(); | ||
function requireAstToSchema(ast, opts) { | ||
if (opts === void 0) { opts = {}; } | ||
var _a; | ||
var sc; | ||
if ((_a = opts) === null || _a === void 0 ? void 0 : _a.schemaComposer) { | ||
if (!opts.schemaComposer) { | ||
throw new Error(dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n Provided option 'schemaComposer' should be an instance of SchemaComposer class from 'graphql-compose' package. \n Recieved:\n ", "\n "], ["\n Provided option 'schemaComposer' should be an instance of SchemaComposer class from 'graphql-compose' package. \n Recieved:\n ", "\n "])), graphql_compose_1.inspect(opts.schemaComposer))); | ||
} | ||
sc = opts.schemaComposer; | ||
} | ||
else { | ||
sc = new graphql_compose_1.SchemaComposer(); | ||
} | ||
if (ast.query) | ||
@@ -46,3 +57,3 @@ populateRoot(sc, 'Query', ast.query); | ||
if (!/^[._a-zA-Z0-9]+$/.test(name)) { | ||
throw new Error("You provide incorrect field name '" + name + "'. It should meet RegExp([._a-zA-Z0-9]+) for '" + ast.absPath + "'"); | ||
throw new Error("You provide incorrect " + (ast.kind === 'file' ? 'file' : 'directory') + " name '" + name + "', it should meet RegExp(/^[._a-zA-Z0-9]+$/) for '" + ast.absPath + "'"); | ||
} | ||
@@ -99,3 +110,3 @@ var typename = getTypename(ast); | ||
if (!ast.code.default) { | ||
throw new Error(dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n NamespaceModule MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'SomeObjectTypeName',\n resolve: () => Date.now(),\n };\n "], ["\n NamespaceModule MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'SomeObjectTypeName',\n resolve: () => Date.now(),\n };\n "])), ast.absPath)); | ||
throw new Error(dedent_1.default(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n NamespaceModule MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'SomeObjectTypeName',\n resolve: () => Date.now(),\n };\n "], ["\n NamespaceModule MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'SomeObjectTypeName',\n resolve: () => Date.now(),\n };\n "])), ast.absPath)); | ||
} | ||
@@ -109,3 +120,3 @@ var fc = ast.code.default; | ||
if (!graphql_compose_1.isOutputTypeDefinitionString(fc.type) && !graphql_compose_1.isTypeNameString(fc.type)) { | ||
throw new Error(dedent_1.default(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n You provide incorrect output type definition:\n ", "\n It must be valid TypeName or output type SDL definition:\n \n Eg.\n type Payload { me: String }\n OR\n Payload\n "], ["\n You provide incorrect output type definition:\n ", "\n It must be valid TypeName or output type SDL definition:\n \n Eg.\n type Payload { me: String }\n OR\n Payload\n "])), fc.type)); | ||
throw new Error(dedent_1.default(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n You provide incorrect output type definition:\n ", "\n It must be valid TypeName or output type SDL definition:\n \n Eg.\n type Payload { me: String }\n OR\n Payload\n "], ["\n You provide incorrect output type definition:\n ", "\n It must be valid TypeName or output type SDL definition:\n \n Eg.\n type Payload { me: String }\n OR\n Payload\n "])), fc.type)); | ||
} | ||
@@ -115,3 +126,3 @@ } | ||
!(fc.type instanceof graphql_1.GraphQLObjectType)) { | ||
throw new Error(dedent_1.default(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n You provide some strange value as 'type':\n ", "\n "], ["\n You provide some strange value as 'type':\n ", "\n "])), graphql_compose_1.inspect(fc.type))); | ||
throw new Error(dedent_1.default(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n You provide some strange value as 'type':\n ", "\n "], ["\n You provide some strange value as 'type':\n ", "\n "])), graphql_compose_1.inspect(fc.type))); | ||
} | ||
@@ -128,6 +139,6 @@ fc.type = sc.createObjectTC(fc.type); | ||
if (!fc) { | ||
throw new Error(dedent_1.default(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n Module MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'String',\n resolve: () => Date.now(),\n };\n "], ["\n Module MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'String',\n resolve: () => Date.now(),\n };\n "])), ast.absPath)); | ||
throw new Error(dedent_1.default(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n Module MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'String',\n resolve: () => Date.now(),\n };\n "], ["\n Module MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'String',\n resolve: () => Date.now(),\n };\n "])), ast.absPath)); | ||
} | ||
if (!fc.type || !isSomeOutputTypeDefinition(fc.type)) { | ||
throw new Error(dedent_1.default(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n Module MUST return FieldConfig with TYPE property in '", "'. \n Eg:\n export default {\n type: 'String'\n };\n "], ["\n Module MUST return FieldConfig with TYPE property in '", "'. \n Eg:\n export default {\n type: 'String'\n };\n "])), ast.absPath)); | ||
throw new Error(dedent_1.default(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n Module MUST return FieldConfig with correct 'type: xxx' property in '", "'. \n Eg:\n export default {\n type: 'String'\n };\n "], ["\n Module MUST return FieldConfig with correct 'type: xxx' property in '", "'. \n Eg:\n export default {\n type: 'String'\n };\n "])), ast.absPath)); | ||
} | ||
@@ -137,7 +148,16 @@ return fc; | ||
function isSomeOutputTypeDefinition(type) { | ||
return ((typeof type === 'string' && | ||
(graphql_compose_1.isSomeOutputTypeDefinitionString(type) || graphql_compose_1.isTypeNameString(type))) || | ||
graphql_compose_1.isComposeOutputType(type)); | ||
if (typeof type === 'string') { | ||
// type: 'String' | ||
return graphql_compose_1.isSomeOutputTypeDefinitionString(type) || graphql_compose_1.isTypeNameString(type); | ||
} | ||
else if (Array.isArray(type)) { | ||
// type: ['String'] | ||
return isSomeOutputTypeDefinition(type[0]); | ||
} | ||
else { | ||
// type: 'type User { name: String }' | ||
return graphql_compose_1.isComposeOutputType(type); | ||
} | ||
} | ||
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5; | ||
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6; | ||
//# sourceMappingURL=requireAstToSchema.js.map |
/// <reference types="node" /> | ||
interface Options { | ||
extensions: string[]; | ||
export interface RequireOptions { | ||
relativePath?: string; | ||
extensions?: string[]; | ||
include?: RegExp | ((path: string, filename: string) => boolean); | ||
@@ -36,6 +37,6 @@ exclude?: RegExp | ((path: string, filename: string) => boolean); | ||
} | ||
export declare const defaultOptions: Options; | ||
export declare function requireSchemaDirectory(m: NodeModule, path?: string, options?: Options): RequireAstResult; | ||
export declare function requireSubDirectory(m: NodeModule, path: string, options?: Options): RequireAstDirNode; | ||
export declare const defaultOptions: RequireOptions; | ||
export declare function requireSchemaDirectory(m: NodeModule, options?: RequireOptions): RequireAstResult; | ||
export declare function requireSubDirectory(m: NodeModule, path: string, options?: RequireOptions): RequireAstDirNode; | ||
export {}; | ||
//# sourceMappingURL=requireSchemaDirectory.d.ts.map |
@@ -22,7 +22,9 @@ "use strict"; | ||
}; | ||
function requireSchemaDirectory(m, path, options) { | ||
function requireSchemaDirectory(m, options) { | ||
if (options === void 0) { options = exports.defaultOptions; } | ||
var _a; | ||
// if no path was passed in, assume the equivelant of __dirname from caller | ||
// otherwise, resolve path relative to the equivalent of __dirname | ||
var schemaPath = !path ? path_1.dirname(m.filename) : path_1.resolve(path_1.dirname(m.filename), path); | ||
var schemaPath = ((_a = options) === null || _a === void 0 ? void 0 : _a.relativePath) ? path_1.resolve(path_1.dirname(m.filename), options.relativePath) | ||
: path_1.dirname(m.filename); | ||
var result = {}; | ||
@@ -75,3 +77,7 @@ fs_1.default.readdirSync(schemaPath).forEach(function (filename) { | ||
var stat = fs_1.default.statSync(absPath); | ||
if (stat.isDirectory()) { | ||
if (skipName(filename)) { | ||
// just skip file/dir | ||
// TODO: add debug here | ||
} | ||
else if (stat.isDirectory()) { | ||
// this node is a directory; recurse | ||
@@ -103,2 +109,5 @@ if (result.children[filename]) { | ||
exports.requireSubDirectory = requireSubDirectory; | ||
function skipName(filename) { | ||
return /^__.*/i.test(filename); | ||
} | ||
function checkFileInclusion(absPath, filename, options) { | ||
@@ -108,2 +117,4 @@ return ( | ||
new RegExp('\\.(' + options.extensions.join('|') + ')$', 'i').test(filename) && | ||
// Hardcoded skip file extensions | ||
!new RegExp('(\\.d\\.ts)$', 'i').test(filename) && | ||
// if options.include is a RegExp, evaluate it and make sure the path passes | ||
@@ -110,0 +121,0 @@ !(options.include && options.include instanceof RegExp && !options.include.test(absPath)) && |
{ | ||
"name": "graphql-compose-modules", | ||
"license": "MIT", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A toolset for construction GraphQL Schema via file structure", | ||
@@ -17,3 +17,3 @@ "repository": "https://github.com/graphql-compose/graphql-compose-modules", | ||
"peerDependencies": { | ||
"graphql-compose": "^7.6.0" | ||
"graphql-compose": "^7.6.1" | ||
}, | ||
@@ -24,11 +24,11 @@ "devDependencies": { | ||
"@types/jest": "24.0.23", | ||
"@types/node": "12.12.11", | ||
"@types/node": "12.12.12", | ||
"@typescript-eslint/eslint-plugin": "2.8.0", | ||
"@typescript-eslint/parser": "2.8.0", | ||
"apollo-server": "^2.9.12", | ||
"eslint": "6.6.0", | ||
"eslint": "6.7.1", | ||
"eslint-config-prettier": "6.7.0", | ||
"eslint-plugin-prettier": "3.1.1", | ||
"graphql": "^14.0.0", | ||
"graphql-compose": "^7.6.0", | ||
"graphql-compose": "^7.6.1", | ||
"jest": "24.9.0", | ||
@@ -39,2 +39,3 @@ "prettier": "1.19.1", | ||
"ts-jest": "24.2.0", | ||
"ts-node": "^8.5.2", | ||
"typescript": "3.7.2" | ||
@@ -51,3 +52,4 @@ }, | ||
"start-example1": "cd ./examples/simple && yarn install && yarn watch", | ||
"start-example2": "cd ./examples/forTests && yarn install && yarn watch" | ||
"start-example2": "cd ./examples/simpleNamespaces && yarn install && yarn watch", | ||
"start-example3": "cd ./examples/forTests && yarn install && yarn watch" | ||
}, | ||
@@ -54,0 +56,0 @@ "collective": { |
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
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
33042
15
359
1
11
19