Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support typescript #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/load_connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ module.exports = app => {
const classes = new Map();

types.forEach(type => {

const connectorFile = path.join(basePath, type, 'connector.js');
const connectorFile = app.loader.resolveModule(path.join(basePath, type, 'connector'));
/* istanbul ignore else */
if (fs.existsSync(connectorFile)) {
const Connector = require(connectorFile);
const Connector = app.loader.loadFile(connectorFile);
classes.set(path.basename(type), Connector);
}
});
Expand Down
21 changes: 7 additions & 14 deletions lib/load_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = app => {

const schemas = [];
const resolverMap = {};
const resolverFactories = [];
const directiveMap = {};
const schemaDirectivesProps = {};
const { defaultEmptySchema = false } = app.config.graphql;
Expand All @@ -39,36 +38,30 @@ module.exports = app => {
}

// Load resolver
const resolverFile = path.join(basePath, type, 'resolver.js');
const resolverFile = app.loader.resolveModule(path.join(basePath, type, 'resolver'));
if (fs.existsSync(resolverFile)) {
const resolver = require(resolverFile);
if (_.isFunction(resolver)) {
resolverFactories.push(resolver);
} else if (_.isObject(resolver)) {
_.merge(resolverMap, resolver);
}
const resolver = app.loader.loadFile(resolverFile);
_.merge(resolverMap, resolver);
}

// Load directive resolver
const directiveFile = path.join(basePath, type, 'directive.js');
const directiveFile = app.loader.resolveModule(path.join(basePath, type, 'directive'));
if (fs.existsSync(directiveFile)) {
const directive = require(directiveFile);
const directive = app.loader.loadFile(directiveFile);
_.merge(directiveMap, directive);
}

// Load schemaDirectives
let schemaDirectivesFile = path.join(basePath, type, 'schemaDirective.js');
let schemaDirectivesFile = app.loader.resolveModule(path.join(basePath, type, 'schemaDirective'));
if (fs.existsSync(schemaDirectivesFile)) {
schemaDirectivesFile = require(schemaDirectivesFile);
schemaDirectivesFile = app.loader.loadFile(schemaDirectivesFile);
_.merge(schemaDirectivesProps, schemaDirectivesFile);
}
});

Object.defineProperty(app, 'schema', {
get() {
if (!this[SYMBOL_SCHEMA]) {
resolverFactories.forEach(resolverFactory => _.merge(resolverMap, resolverFactory(app)));

this[SYMBOL_SCHEMA] = makeExecutableSchema({
typeDefs: schemas,
resolvers: resolverMap,
Expand Down