Skip to Content
GraphQL Tools
DocumentationAPI@graphql-tools/mocksrcfunctionsmockServer

Function: mockServer()

mockServer<TResolvers>(schema, mocks, preserveResolvers?, mockGenerationBehavior?): IMockServer

Defined in: packages/mock/src/mockServer.ts:21

A convenience wrapper on top of addMocksToSchema. It adds your mock resolvers to your schema and returns a client that will correctly execute your query with variables. Note: when executing queries from the returned server, context and root will both equal {}.

Type Parameters

TResolvers

TResolvers

Parameters

schema

TypeSource

The schema to which to add mocks. This can also be a set of type definitions instead.

mocks

IMocks<TResolvers>

The mocks to add to the schema.

preserveResolvers?

boolean = false

Set to true to prevent existing resolvers from being overwritten to provide mock data. This can be used to mock some parts of the server and not others.

mockGenerationBehavior?

MockGenerationBehavior

Set to 'deterministic' if the default random mock generation behavior causes flakiness.

Returns

IMockServer