How to use the graphql-tools.addErrorLoggingToSchema function in graphql-tools

To help you get started, we’ve selected a few graphql-tools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apollographql / apollo-server / src / apolloServer.js View on Github external
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,
github apollographql / apollo-server / src / apolloServer.js View on Github external
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,
github apollographql / apollo-server / src / apolloServer.js View on Github external
} 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');
          }
github cdmbase / fullstack-pro / servers / backend-server / src / api / schema-builder.ts View on Github external
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;
    }
github cdmbase / fullstack-pro / servers / backend-server / src / api / schema.ts View on Github external
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 };
github CodeCommission / subkit / lib / index.js View on Github external
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)) {
github BigFatDog / auth-flow-react-apollo-saga / server / api / index.js View on Github external
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;
github 10thfloor / astrolab / imports / api / index.ts View on Github external
export default (): void => {
  const schema = makeExecutableSchema({
    typeDefs,
    resolvers,
  })
  addErrorLoggingToSchema(schema, logger)
  createApolloServer({
    schema,
  })
}