Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
addResolveFunctionsToSchema(executableSchema, resolvers || {});
addMockFunctionsToSchema({
schema: executableSchema,
mocks: myMocks,
preserveResolvers: true,
});
} else {
// this is just basics, makeExecutableSchema should catch the rest
// TODO: should be able to provide a GraphQLschema and still use resolvers
// and connectors if you want, but at the moment this is not possible.
if (schema instanceof GraphQLSchema) {
if (logger) {
addErrorLoggingToSchema(schema, logger);
}
if (printErrors) {
addErrorLoggingToSchema(schema, { log: (e) => console.error(e.stack) });
}
if (!allowUndefinedInResolve) {
addCatchUndefinedToSchema(schema);
}
executableSchema = schema;
if (resolvers) {
addResolveFunctionsToSchema(executableSchema, resolvers);
}
} else {
if (!resolvers) {
// TODO: test this error
throw new Error('resolvers is required option if mocks is not provided');
}
executableSchema = makeExecutableSchema({
typeDefs: schema,
resolvers,
addResolveFunctionsToSchema(executableSchema, resolvers);
}
} else {
if (!resolvers) {
// TODO: test this error
throw new Error('resolvers is required option if mocks is not provided');
}
executableSchema = makeExecutableSchema({
typeDefs: schema,
resolvers,
connectors,
logger,
allowUndefinedInResolve,
});
if (printErrors) {
addErrorLoggingToSchema(executableSchema, { log: (e) => console.error(e.stack) });
}
}
}
// Tracer-related stuff ------------------------------------------------
tracerLogger = { log: undefined, report: undefined };
if (tracer) {
tracerLogger = tracer.newLoggerInstance();
tracerLogger.log('request.info', {
headers: req.headers,
baseUrl: req.baseUrl,
originalUrl: req.originalUrl,
method: req.method,
httpVersion: req.httpVersion,
remoteAddr: req.connection.remoteAddress,
} else {
executableSchema = buildSchemaFromTypeDefinitions(schema);
}
addResolveFunctionsToSchema(executableSchema, resolvers || {});
addMockFunctionsToSchema({
schema: executableSchema,
mocks: myMocks,
preserveResolvers: true,
});
} else {
// this is just basics, makeExecutableSchema should catch the rest
// TODO: should be able to provide a GraphQLschema and still use resolvers
// and connectors if you want, but at the moment this is not possible.
if (schema instanceof GraphQLSchema) {
if (logger) {
addErrorLoggingToSchema(schema, logger);
}
if (printErrors) {
addErrorLoggingToSchema(schema, { log: (e) => console.error(e.stack) });
}
if (!allowUndefinedInResolve) {
addCatchUndefinedToSchema(schema);
}
executableSchema = schema;
if (resolvers) {
addResolveFunctionsToSchema(executableSchema, resolvers);
}
} else {
if (!resolvers) {
// TODO: test this error
throw new Error('resolvers is required option if mocks is not provided');
}
public async build(): Promise {
let schema, ownSchema;
try {
ownSchema = this.createOwnSchema();
let remoteSchema = await this.load();
// techSchema = this.patchSchema(techSchema, 'TechService');
schema = mergeSchemas({
schemas: [
ownSchema,
remoteSchema,
],
});
addErrorLoggingToSchema(schema, { log: (e) => logger.error(e) });
} catch (err) {
logger.warn('errors when building schema::', err.message);
schema = ownSchema;
}
return schema;
}
AnyObject: GraphQLAnyObject,
};
const resolverOptions: IResolverOptions = {
pubsub,
logger,
};
console.log('schemas', modules.schemas);
const schema: GraphQLSchema = makeExecutableSchema({
resolvers: _.merge(resolvers(pubsub, logger), modules.createResolvers(resolverOptions)),
typeDefs: [rootSchemaDef].concat(typeDefs).concat(modules.schemas) as Array,
});
addErrorLoggingToSchema(schema, { log: (e) => logger.error(e) });
addMockFunctionsToSchema({
mocks: {},
preserveResolvers: true,
schema,
});
export { schema };
const schema = makeExecutableSchema({
typeDefs: ['scalar JSON'].concat(schemaDefinitionFiles),
resolvers: Object.assign(
{},
{JSON: GraphQLJSON},
resolverDefinition.resolvers
)
});
addCustomDirectivesToSchema(
schema,
Object.assign({}, subkitDirectives, resolverDefinition.directives)
);
addErrorLoggingToSchema(schema, {
log: e => {
if (app.logFormat === 'text') return console.error(e.message);
if (app.logFormat === 'json')
return console.error(
JSON.stringify({
message: e.message,
error: e,
stack: e.stack,
type: 'Error'
})
);
}
});
app.use('/graphql', (req, res, next) => {
if (Boolean(app.graphiql)) {
import { addErrorLoggingToSchema, makeExecutableSchema } from 'graphql-tools';
import merge from 'lodash/merge';
import logger from '../logger';
import pubsub from './pubsub';
import Posts from './posts';
const ApiList = [Posts];
const apiSchema = makeExecutableSchema({
typeDefs: ApiList.map(d => d.typeDefs),
resolvers: merge({}, ...ApiList.map(d => d.createResolvers(pubsub))),
resolverValidationOptions: { requireResolversForAllFields: false },
});
addErrorLoggingToSchema(apiSchema, { log: e => logger.error(e) });
export default apiSchema;
export default (): void => {
const schema = makeExecutableSchema({
typeDefs,
resolvers,
})
addErrorLoggingToSchema(schema, logger)
createApolloServer({
schema,
})
}