1 | import { GraphQLSchema } from 'graphql';
|
2 | import { IResolvers } from '@graphql-tools/utils';
|
3 | import { IMockStore, IMocks, TypePolicy } from './types.js';
|
4 | declare type IMockOptions<TResolvers = IResolvers> = {
|
5 | schema: GraphQLSchema;
|
6 | store?: IMockStore;
|
7 | mocks?: IMocks<TResolvers>;
|
8 | typePolicies?: {
|
9 | [typeName: string]: TypePolicy;
|
10 | };
|
11 | resolvers?: Partial<TResolvers> | ((store: IMockStore) => Partial<TResolvers>);
|
12 | /**
|
13 | * Set to `true` to prevent existing resolvers from being
|
14 | * overwritten to provide mock data. This can be used to mock some parts of the
|
15 | * server and not others.
|
16 | */
|
17 | preserveResolvers?: boolean;
|
18 | };
|
19 | /**
|
20 | * Given a `schema` and a `MockStore`, returns an executable schema that
|
21 | * will use the provided `MockStore` to execute queries.
|
22 | *
|
23 | * ```ts
|
24 | * const schema = buildSchema(`
|
25 | * type User {
|
26 | * id: ID!
|
27 | * name: String!
|
28 | * }
|
29 | * type Query {
|
30 | * me: User!
|
31 | * }
|
32 | * `)
|
33 | *
|
34 | * const store = createMockStore({ schema });
|
35 | * const mockedSchema = addMocksToSchema({ schema, store });
|
36 | * ```
|
37 | *
|
38 | *
|
39 | * If a `resolvers` parameter is passed, the query execution will use
|
40 | * the provided `resolvers` if, one exists, instead of the default mock
|
41 | * resolver.
|
42 | *
|
43 | *
|
44 | * ```ts
|
45 | * const schema = buildSchema(`
|
46 | * type User {
|
47 | * id: ID!
|
48 | * name: String!
|
49 | * }
|
50 | * type Query {
|
51 | * me: User!
|
52 | * }
|
53 | * type Mutation {
|
54 | * setMyName(newName: String!): User!
|
55 | * }
|
56 | * `)
|
57 | *
|
58 | * const store = createMockStore({ schema });
|
59 | * const mockedSchema = addMocksToSchema({
|
60 | * schema,
|
61 | * store,
|
62 | * resolvers: {
|
63 | * Mutation: {
|
64 | * setMyName: (_, { newName }) => {
|
65 | * const ref = store.get('Query', 'ROOT', 'viewer');
|
66 | * store.set(ref, 'name', newName);
|
67 | * return ref;
|
68 | * }
|
69 | * }
|
70 | * }
|
71 | * });
|
72 | * ```
|
73 | *
|
74 | *
|
75 | * `Query` and `Mutation` type will use `key` `'ROOT'`.
|
76 | */
|
77 | export declare function addMocksToSchema<TResolvers = IResolvers>({ schema, store: maybeStore, mocks, typePolicies, resolvers: resolversOrFnResolvers, preserveResolvers, }: IMockOptions<TResolvers>): GraphQLSchema;
|
78 | export {};
|
79 |
|
\ | No newline at end of file |