@graphql-tools/mock 8.3.2-alpha-5d885fa3.0 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/MockStore.d.ts CHANGED
@@ -22,6 +22,7 @@ export declare class MockStore implements IMockStore {
22
22
  [typeName: string]: TypePolicy;
23
23
  };
24
24
  });
25
+ has<KeyT extends KeyTypeConstraints = string>(typeName: string, key: KeyT): boolean;
25
26
  get<KeyT extends KeyTypeConstraints = string, ReturnKeyT extends KeyTypeConstraints = string>(_typeName: string | Ref<KeyT> | GetArgs<KeyT>, _key?: KeyT | {
26
27
  [fieldName: string]: any;
27
28
  } | string | string[], _fieldName?: string | string[] | {
package/index.js CHANGED
@@ -145,6 +145,9 @@ class MockStore {
145
145
  this.mocks = { ...defaultMocks, ...mocks };
146
146
  this.typePolicies = typePolicies || {};
147
147
  }
148
+ has(typeName, key) {
149
+ return !!this.store[typeName] && !!this.store[typeName][key];
150
+ }
148
151
  get(_typeName, _key, _fieldName, _fieldArgs) {
149
152
  if (typeof _typeName !== 'string') {
150
153
  if (_key === undefined) {
package/index.mjs CHANGED
@@ -139,6 +139,9 @@ class MockStore {
139
139
  this.mocks = { ...defaultMocks, ...mocks };
140
140
  this.typePolicies = typePolicies || {};
141
141
  }
142
+ has(typeName, key) {
143
+ return !!this.store[typeName] && !!this.store[typeName][key];
144
+ }
142
145
  get(_typeName, _key, _fieldName, _fieldArgs) {
143
146
  if (typeof _typeName !== 'string') {
144
147
  if (_key === undefined) {
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@graphql-tools/mock",
3
- "version": "8.3.2-alpha-5d885fa3.0",
3
+ "version": "8.4.0",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@graphql-tools/schema": "8.2.1-alpha-5d885fa3.0",
11
- "@graphql-tools/utils": "^8.2.0",
10
+ "@graphql-tools/schema": "^8.2.0",
11
+ "@graphql-tools/utils": "^8.2.3",
12
12
  "fast-json-stable-stringify": "^2.1.0",
13
13
  "tslib": "~2.3.0"
14
14
  },
package/types.d.ts CHANGED
@@ -168,6 +168,10 @@ export interface IMockStore {
168
168
  set<KeyT extends KeyTypeConstraints = string>(ref: Ref<KeyT>, values: {
169
169
  [fieldName: string]: any;
170
170
  }): void;
171
+ /**
172
+ * Checks if a mock is present in the store for the given typeName and key.
173
+ */
174
+ has<KeyT extends KeyTypeConstraints = string>(typeName: string, key: KeyT): boolean;
171
175
  /**
172
176
  * Resets the mock store
173
177
  */
package/es5/MockList.d.ts DELETED
@@ -1,25 +0,0 @@
1
- /**
2
- * @internal
3
- */
4
- export declare function isMockList(obj: any): obj is MockList;
5
- /**
6
- * This is an object you can return from your mock resolvers which calls the
7
- * provided `mockFunction` once for each list item.
8
- */
9
- export declare class MockList {
10
- private readonly len;
11
- private readonly wrappedFunction;
12
- /**
13
- * @param length Either the exact length of items to return or an inclusive
14
- * range of possible lengths.
15
- * @param mockFunction The function to call for each item in the list to
16
- * resolve it. It can return another MockList or a value.
17
- */
18
- constructor(length: number | Array<number>, mockFunction?: () => unknown);
19
- /**
20
- * @internal
21
- */
22
- mock(): unknown[];
23
- private randint;
24
- }
25
- export declare function deepResolveMockList(mockList: MockList): unknown[];
@@ -1,93 +0,0 @@
1
- import { GraphQLSchema } from 'graphql';
2
- import { IMockStore, GetArgs, SetArgs, Ref, TypePolicy, IMocks, KeyTypeConstraints } from './types';
3
- export declare const defaultMocks: {
4
- Int: () => number;
5
- Float: () => number;
6
- String: () => string;
7
- Boolean: () => boolean;
8
- ID: () => string;
9
- };
10
- declare type Entity = {
11
- [key: string]: unknown;
12
- };
13
- export declare class MockStore implements IMockStore {
14
- schema: GraphQLSchema;
15
- private mocks;
16
- private typePolicies;
17
- private store;
18
- constructor({ schema, mocks, typePolicies, }: {
19
- schema: GraphQLSchema;
20
- mocks?: IMocks;
21
- typePolicies?: {
22
- [typeName: string]: TypePolicy;
23
- };
24
- });
25
- get<KeyT extends KeyTypeConstraints = string, ReturnKeyT extends KeyTypeConstraints = string>(_typeName: string | Ref<KeyT> | GetArgs<KeyT>, _key?: KeyT | {
26
- [fieldName: string]: any;
27
- } | string | string[], _fieldName?: string | string[] | {
28
- [fieldName: string]: any;
29
- } | string | {
30
- [argName: string]: any;
31
- }, _fieldArgs?: string | {
32
- [argName: string]: any;
33
- }): unknown | Ref<ReturnKeyT>;
34
- set<KeyT extends KeyTypeConstraints>(_typeName: string | Ref<KeyT> | SetArgs<KeyT>, _key?: KeyT | string | {
35
- [fieldName: string]: any;
36
- }, _fieldName?: string | {
37
- [fieldName: string]: any;
38
- } | unknown, _value?: unknown): void;
39
- reset(): void;
40
- filter(key: string, predicate: (val: Entity) => boolean): Entity[];
41
- find(key: string, predicate: (val: Entity) => boolean): Entity | undefined;
42
- private getImpl;
43
- private setImpl;
44
- private normalizeValueToStore;
45
- private insert;
46
- private generateFieldValue;
47
- private generateFieldValueFromMocks;
48
- private generateKeyForType;
49
- private generateValueFromType;
50
- private getFieldType;
51
- private getType;
52
- private isKeyField;
53
- private getKeyFieldName;
54
- }
55
- /**
56
- * Will create `MockStore` for the given `schema`.
57
- *
58
- * A `MockStore` will generate mock values for the given schem when queried.
59
- *
60
- * It will stores generated mocks, so that, provided with same arguments
61
- * the returned values will be the same.
62
- *
63
- * Its API also allows to modify the stored values.
64
- *
65
- * Basic example:
66
- * ```ts
67
- * store.get('User', 1, 'name');
68
- * // > "Hello World"
69
- * store.set('User', 1, 'name', 'Alexandre');
70
- * store.get('User', 1, 'name');
71
- * // > "Alexandre"
72
- * ```
73
- *
74
- * The storage key will correspond to the "key field"
75
- * of the type. Field with name `id` or `_id` will be
76
- * by default considered as the key field for the type.
77
- * However, use `typePolicies` to precise the field to use
78
- * as key.
79
- */
80
- export declare function createMockStore(options: {
81
- /**
82
- * The `schema` to based mocks on.
83
- */
84
- schema: GraphQLSchema;
85
- /**
86
- * The mocks functions to use.
87
- */
88
- mocks?: IMocks;
89
- typePolicies?: {
90
- [typeName: string]: TypePolicy;
91
- };
92
- }): IMockStore;
93
- export {};
package/es5/README.md DELETED
@@ -1,5 +0,0 @@
1
- Check API Reference for more information about this package;
2
- https://www.graphql-tools.com/docs/api/modules/mock
3
-
4
- You can also learn more about Mocking in this chapter;
5
- https://www.graphql-tools.com/docs/mocking
@@ -1,78 +0,0 @@
1
- import { GraphQLSchema } from 'graphql';
2
- import { IResolvers } from '@graphql-tools/utils';
3
- import { IMockStore, IMocks, TypePolicy } from './types';
4
- declare type IMockOptions = {
5
- schema: GraphQLSchema;
6
- store?: IMockStore;
7
- mocks?: IMocks;
8
- typePolicies?: {
9
- [typeName: string]: TypePolicy;
10
- };
11
- resolvers?: IResolvers | ((store: IMockStore) => IResolvers);
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({ schema, store: maybeStore, mocks, typePolicies, resolvers: resolversOrFnResolvers, preserveResolvers, }: IMockOptions): GraphQLSchema;
78
- export {};
package/es5/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './MockStore';
2
- export * from './addMocksToSchema';
3
- export * from './mockServer';
4
- export * from './types';
5
- export * from './MockList';