How to use the graphql-tools.addMockFunctionsToSchema 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 tomitrescak / apollo-mobx / src / testing / index.tsx View on Github external
mutations = {},
  resolvers = {},
  reducers = {},
  typeDefs = global.globalTypeDefs,
  context,
  loadingComponent
}: ApolloProps) {
  // add crap around mocks
  const finalMocks = {
    ...resolvers,
    Mutation: () => mutations || {},
    Query: () => queries || {},
  };

  const schema = makeExecutableSchema({ typeDefs, resolvers: global.globalResolvers });
  addMockFunctionsToSchema({
    mocks: finalMocks,
    schema,
  });

  const apolloCache = new InMemoryCache(global.__APOLLO_STATE_);

  const spyLink = new SpyLink();
  const graphqlClient: ApolloClient = new ApolloClient({
    cache: apolloCache as any,
    context,
    link: ApolloLink.from([
      spyLink,
      new MockLink({ schema }),
    ]),
    loadingComponent
  });
github apollographql / apollo-server / packages / apollo-server-core / src / ApolloServer.ts View on Github external
private generateSchemaDerivedData(schema: GraphQLSchema): SchemaDerivedData {
    const schemaHash = generateSchemaHash(schema!);

    const { mocks, mockEntireSchema, extensions: _extensions } = this.config;

    if (mocks || (typeof mockEntireSchema !== 'undefined' && mocks !== false)) {
      addMockFunctionsToSchema({
        schema,
        mocks:
          typeof mocks === 'boolean' || typeof mocks === 'undefined'
            ? {}
            : mocks,
        preserveResolvers:
          typeof mockEntireSchema === 'undefined' ? false : !mockEntireSchema,
      });
    }

    const extensions = [];

    const schemaIsFederated = this.schemaIsFederated(schema);
    const { engine } = this.config;
    // Keep this extension second so it wraps everything, except error formatting
    if (this.engineReportingAgent) {
github atomicobject / ts-react-graphql-starter-kit / modules / client / test-helpers / mock-apollo.tsx View on Github external
export function mockClient(mocks: MockDefinitions): ApolloClient {
  const exSchema = makeExecutableSchema({ typeDefs: rawSchema });
  addMockFunctionsToSchema({
    schema: exSchema,
    mocks: mocks as any
  });

  const netInterface = mockNetworkInterfaceWithSchema({ schema: exSchema });
  const client = new ApolloClient({
    networkInterface: netInterface
  });
  return client;
}
github HigoRibeiro / adonis-gql / src / Server / index.js View on Github external
handle (context, options = {}) {
    if (!this.$schema) {
      throw new Error('Schema has not been defined')
    }

    if (options.mocks) {
      addMockFunctionsToSchema({
        schema: this.$schema,
        preserveResolvers: false
      })
    }

    return graphqlAdonis({
      context,
      schema: this.$schema
    })(context)
  }
github caioreis123 / market2 / backend2 / node_modules / apollo-server-core / dist / ApolloServer.js View on Github external
throw Error('Apollo Server requires either an existing schema or typeDefs');
            }
            this.schema = graphql_tools_1.makeExecutableSchema({
                typeDefs: this.uploadsConfig
                    ? [
                        index_1.gql `
                scalar Upload
              `,
                    ].concat(typeDefs)
                    : typeDefs,
                schemaDirectives,
                resolvers,
            });
        }
        if (mocks) {
            graphql_tools_1.addMockFunctionsToSchema({
                schema: this.schema,
                preserveResolvers: true,
                mocks: typeof mocks === 'boolean' ? {} : mocks,
            });
        }
        this.extensions = [];
        if (this.requestOptions.formatError) {
            this.extensions.push(() => new formatters_1.FormatErrorExtension(this.requestOptions.formatError, this.requestOptions.debug));
        }
        if (engine || (engine !== false && process.env.ENGINE_API_KEY)) {
            this.engineReportingAgent = new apollo_engine_reporting_1.EngineReportingAgent(engine === true ? {} : engine);
            this.extensions.push(() => this.engineReportingAgent.newExtension());
        }
        if (extensions) {
            this.extensions = [...this.extensions, ...extensions];
        }
github jefflau / apollo-client-mock / index.js View on Github external
return function createClient(overwriteMocks = {}) {
    const mergedMocks = merge({...mockResolvers}, overwriteMocks)

    const schema = makeExecutableSchema({ typeDefs })
    addMockFunctionsToSchema({
      schema,
      mocks: mergedMocks
    })

    const apolloCache = new InMemoryCache(window.__APOLLO_STATE__)

    const graphqlClient = new ApolloClient({
      cache: apolloCache,
      link: new SchemaLink({ schema })
    })

    return graphqlClient
  }
}
github ExpediaGroup / graphql-component / lib / index.js View on Github external
const makeSchema = this._federation ? buildFederatedSchema : makeExecutableSchema;

    const schema = makeSchema({
      typeDefs,
      resolvers,
      schemaDirectives
    });

    debug(`created ${this.constructor.name} schema`);

    if (this._useMocks) {
      debug(`adding mocks, preserveResolvers=${this._preserveResolvers}`);

      const mocks = Object.assign({}, this._importedMocks, this._mocks);

      addMockFunctionsToSchema({ schema, mocks, preserveResolvers: this._preserveResolvers });
    }

    this._schema = schema;

    return this._schema;
  }
github abhiaiyer91 / apollo-storybook-decorator / packages / apollo-storybook-v1 / src / index.js View on Github external
export default function initializeApollo({
  typeDefs,
  mocks,
  reducers = {},
  reduxMiddlewares = [],
  apolloClientOptions = {},
  typeResolvers,
  context = {},
  rootValue = {},
}) {
  const schema = makeExecutableSchema({ typeDefs });
  if (!!mocks) {
    addMockFunctionsToSchema({
      schema,
      mocks,
    });
  }

  if (!!typeResolvers) {
    addResolveFunctionsToSchema(schema, typeResolvers);
  }

  const graphqlClient = new ApolloClient({
    addTypename: true,
    networkInterface: {
      query(request) {
        return graphql(
          schema,
          print(request.query),
github rricard / movieql / data / schema.js View on Github external
} from 'graphql-tools';

import typeDefs from './definitions';
import resolvers from './resolvers';
import mocks from './mocks';

const isMocked = !process.env.MOVIE_DB_TOKEN ||
  !process.env.SFDC_PWD_AND_TOKEN ||
  !process.env.SFDC_USERNAME;

const schema = makeExecutableSchema({
  typeDefs,
  resolvers,
});

isMocked && addMockFunctionsToSchema({schema, mocks});

export default schema;