@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 +1 -0
- package/index.js +3 -0
- package/index.mjs +3 -0
- package/package.json +3 -3
- package/types.d.ts +4 -0
- package/es5/MockList.d.ts +0 -25
- package/es5/MockStore.d.ts +0 -93
- package/es5/README.md +0 -5
- package/es5/addMocksToSchema.d.ts +0 -78
- package/es5/index.d.ts +0 -5
- package/es5/index.js +0 -901
- package/es5/index.mjs +0 -885
- package/es5/mockServer.d.ts +0 -15
- package/es5/package.json +0 -37
- package/es5/types.d.ts +0 -194
- package/es5/utils.d.ts +0 -8
package/es5/mockServer.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { TypeSource } from '@graphql-tools/utils';
|
|
2
|
-
import { IMockServer, IMocks } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* A convenience wrapper on top of addMocksToSchema. It adds your mock resolvers
|
|
5
|
-
* to your schema and returns a client that will correctly execute your query with
|
|
6
|
-
* variables. Note: when executing queries from the returned server, context and
|
|
7
|
-
* root will both equal `{}`.
|
|
8
|
-
* @param schema The schema to which to add mocks. This can also be a set of type
|
|
9
|
-
* definitions instead.
|
|
10
|
-
* @param mocks The mocks to add to the schema.
|
|
11
|
-
* @param preserveResolvers Set to `true` to prevent existing resolvers from being
|
|
12
|
-
* overwritten to provide mock data. This can be used to mock some parts of the
|
|
13
|
-
* server and not others.
|
|
14
|
-
*/
|
|
15
|
-
export declare function mockServer(schema: TypeSource, mocks: IMocks, preserveResolvers?: boolean): IMockServer;
|
package/es5/package.json
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@graphql-tools/mock/es5",
|
|
3
|
-
"version": "8.3.2-alpha-5d885fa3.0",
|
|
4
|
-
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
|
-
"sideEffects": false,
|
|
6
|
-
"peerDependencies": {
|
|
7
|
-
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
|
-
},
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"@graphql-tools/schema": "8.2.1-alpha-5d885fa3.0",
|
|
11
|
-
"@graphql-tools/utils": "^8.2.0",
|
|
12
|
-
"fast-json-stable-stringify": "^2.1.0",
|
|
13
|
-
"tslib": "~2.3.0"
|
|
14
|
-
},
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "ardatan/graphql-tools",
|
|
18
|
-
"directory": "packages/mock"
|
|
19
|
-
},
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"main": "index.js",
|
|
22
|
-
"module": "index.mjs",
|
|
23
|
-
"typings": "index.d.ts",
|
|
24
|
-
"typescript": {
|
|
25
|
-
"definition": "index.d.ts"
|
|
26
|
-
},
|
|
27
|
-
"exports": {
|
|
28
|
-
".": {
|
|
29
|
-
"require": "./index.js",
|
|
30
|
-
"import": "./index.mjs"
|
|
31
|
-
},
|
|
32
|
-
"./*": {
|
|
33
|
-
"require": "./*.js",
|
|
34
|
-
"import": "./*.mjs"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
package/es5/types.d.ts
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { ExecutionResult, GraphQLSchema } from 'graphql';
|
|
2
|
-
export declare type IMockFn = () => unknown;
|
|
3
|
-
export declare type IScalarMock = unknown | IMockFn;
|
|
4
|
-
export declare type ITypeMock = () => {
|
|
5
|
-
[fieldName: string]: unknown | IMockFn;
|
|
6
|
-
} | {
|
|
7
|
-
[fieldName: string]: IMockFn;
|
|
8
|
-
};
|
|
9
|
-
export declare type IMocks = {
|
|
10
|
-
[typeOrScalarName: string]: IScalarMock | ITypeMock;
|
|
11
|
-
};
|
|
12
|
-
export declare type KeyTypeConstraints = string | number;
|
|
13
|
-
export declare type TypePolicy = {
|
|
14
|
-
/**
|
|
15
|
-
* The name of the field that should be used as store `key`.
|
|
16
|
-
*
|
|
17
|
-
* If `false`, no field will be used and `id` or `_id` will be used,
|
|
18
|
-
* otherwise we'll generate a random string
|
|
19
|
-
* as key.
|
|
20
|
-
*/
|
|
21
|
-
keyFieldName?: string | false;
|
|
22
|
-
};
|
|
23
|
-
export declare type GetArgs<KeyT extends KeyTypeConstraints = string> = {
|
|
24
|
-
typeName: string;
|
|
25
|
-
key?: KeyT;
|
|
26
|
-
fieldName?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Optional arguments when querying the field.
|
|
29
|
-
*
|
|
30
|
-
* Querying the field with the same arguments will return
|
|
31
|
-
* the same value. Deep equality is checked.
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* store.get('User', 1, 'friend', { id: 2 }) === store.get('User', 1, 'friend', { id: 2 })
|
|
35
|
-
* store.get('User', 1, 'friend', { id: 2 }) !== store.get('User', 1, 'friend')
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* Args can be a record, just like `args` argument of field resolver or an
|
|
39
|
-
* arbitrary string.
|
|
40
|
-
*/
|
|
41
|
-
fieldArgs?: string | {
|
|
42
|
-
[argName: string]: any;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* If no value found, insert the `defaultValue`.
|
|
46
|
-
*/
|
|
47
|
-
defaultValue?: unknown | {
|
|
48
|
-
[fieldName: string]: any;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
export declare type SetArgs<KeyT extends KeyTypeConstraints = string> = {
|
|
52
|
-
typeName: string;
|
|
53
|
-
key: KeyT;
|
|
54
|
-
fieldName?: string;
|
|
55
|
-
/**
|
|
56
|
-
* Optional arguments when querying the field.
|
|
57
|
-
*
|
|
58
|
-
* @see GetArgs#fieldArgs
|
|
59
|
-
*/
|
|
60
|
-
fieldArgs?: string | {
|
|
61
|
-
[argName: string]: any;
|
|
62
|
-
};
|
|
63
|
-
value?: unknown | {
|
|
64
|
-
[fieldName: string]: any;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* If the value for this field is already set, it won't
|
|
68
|
-
* be overridden.
|
|
69
|
-
*
|
|
70
|
-
* Propagates down do nested `set`.
|
|
71
|
-
*/
|
|
72
|
-
noOverride?: boolean;
|
|
73
|
-
};
|
|
74
|
-
export interface IMockStore {
|
|
75
|
-
schema: GraphQLSchema;
|
|
76
|
-
/**
|
|
77
|
-
* Get a field value from the store for the given type, key and field
|
|
78
|
-
* name — and optionally field arguments. If the field name is not given,
|
|
79
|
-
* a reference to the type will be returned.
|
|
80
|
-
*
|
|
81
|
-
* If the the value for this field is not set, a value will be
|
|
82
|
-
* generated according to field return type and mock functions.
|
|
83
|
-
*
|
|
84
|
-
* If the field's output type is a `ObjectType` (or list of `ObjectType`),
|
|
85
|
-
* it will return a `Ref` (or array of `Ref`), ie a reference to an entity
|
|
86
|
-
* in the store.
|
|
87
|
-
*
|
|
88
|
-
* Example:
|
|
89
|
-
* ```ts
|
|
90
|
-
* store.get('Query', 'ROOT', 'viewer');
|
|
91
|
-
* > { $ref: { key: 'abc-737dh-djdjd', typeName: 'User' } }
|
|
92
|
-
* store.get('User', 'abc-737dh-djdjd', 'name')
|
|
93
|
-
* > "Hello World"
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
get<KeyT extends KeyTypeConstraints = string, ReturnKeyT extends KeyTypeConstraints = string>(args: GetArgs<KeyT>): unknown | Ref<ReturnKeyT>;
|
|
97
|
-
/**
|
|
98
|
-
* Shorthand for `get({typeName, key, fieldName, fieldArgs})`.
|
|
99
|
-
*/
|
|
100
|
-
get<KeyT extends KeyTypeConstraints = string, ReturnKeyT extends KeyTypeConstraints = string>(typeName: string, key: KeyT, fieldNameOrFieldNames: string | string[], fieldArgs?: string | {
|
|
101
|
-
[argName: string]: any;
|
|
102
|
-
}): unknown | Ref<ReturnKeyT>;
|
|
103
|
-
/**
|
|
104
|
-
* Get a reference to the type.
|
|
105
|
-
*/
|
|
106
|
-
get<KeyT extends KeyTypeConstraints = string>(typeName: string, keyOrDefaultValue?: KeyT | {
|
|
107
|
-
[fieldName: string]: any;
|
|
108
|
-
}, defaultValue?: {
|
|
109
|
-
[fieldName: string]: any;
|
|
110
|
-
}): unknown | Ref<KeyT>;
|
|
111
|
-
/**
|
|
112
|
-
* Shorthand for `get({typeName: ref.$ref.typeName, key: ref.$ref.key, fieldName, fieldArgs})`
|
|
113
|
-
* @param ref
|
|
114
|
-
* @param fieldNameOrFieldNames
|
|
115
|
-
* @param fieldArgs
|
|
116
|
-
*/
|
|
117
|
-
get<KeyT extends KeyTypeConstraints = string, ReturnKeyT extends KeyTypeConstraints = string>(ref: Ref<KeyT>, fieldNameOrFieldNames: string | string[], fieldArgs?: string | {
|
|
118
|
-
[argName: string]: any;
|
|
119
|
-
}): unknown | Ref<ReturnKeyT>;
|
|
120
|
-
/**
|
|
121
|
-
* Set a field value in the store for the given type, key and field
|
|
122
|
-
* name — and optionally field arguments.
|
|
123
|
-
*
|
|
124
|
-
* If the the field return type is an `ObjectType` or a list of
|
|
125
|
-
* `ObjectType`, you can set references to other entity as value:
|
|
126
|
-
*
|
|
127
|
-
* ```ts
|
|
128
|
-
* // set the viewer name
|
|
129
|
-
* store.set('User', 1, 'name', 'Alexandre);
|
|
130
|
-
* store.set('Query', 'ROOT', 'viewer', store.get('User', 1));
|
|
131
|
-
*
|
|
132
|
-
* // set the friends of viewer
|
|
133
|
-
* store.set('User', 2, 'name', 'Emily');
|
|
134
|
-
* store.set('User', 3, 'name', 'Caroline');
|
|
135
|
-
* store.set('User', 1, 'friends', [store.get('User', 2), store.get('User', 3)]);
|
|
136
|
-
* ```
|
|
137
|
-
*
|
|
138
|
-
* But it also supports nested set:
|
|
139
|
-
*
|
|
140
|
-
* ```ts
|
|
141
|
-
* store.set('Query', 'ROOT', 'viewer', {
|
|
142
|
-
* name: 'Alexandre',
|
|
143
|
-
* friends: [
|
|
144
|
-
* { name: 'Emily' }
|
|
145
|
-
* { name: 'Caroline }
|
|
146
|
-
* ]
|
|
147
|
-
* });
|
|
148
|
-
* ```
|
|
149
|
-
*/
|
|
150
|
-
set<KeyT extends KeyTypeConstraints = string>(args: SetArgs<KeyT>): void;
|
|
151
|
-
/**
|
|
152
|
-
* Shorthand for `set({typeName, key, fieldName, value})`.
|
|
153
|
-
*/
|
|
154
|
-
set<KeyT extends KeyTypeConstraints = string>(typeName: string, key: KeyT, fieldName: string, value?: unknown): void;
|
|
155
|
-
/**
|
|
156
|
-
* Set the given field values to the type with key.
|
|
157
|
-
*/
|
|
158
|
-
set<KeyT extends KeyTypeConstraints = string>(typeName: string, key: KeyT, values: {
|
|
159
|
-
[fieldName: string]: any;
|
|
160
|
-
}): void;
|
|
161
|
-
/**
|
|
162
|
-
* Shorthand for `set({ref.$ref.typeName, ref.$ref.key, fieldName, value})`.
|
|
163
|
-
*/
|
|
164
|
-
set<KeyT extends KeyTypeConstraints = string>(ref: Ref<KeyT>, fieldName: string, value?: unknown): void;
|
|
165
|
-
/**
|
|
166
|
-
* Set the given field values to the type with ref.
|
|
167
|
-
*/
|
|
168
|
-
set<KeyT extends KeyTypeConstraints = string>(ref: Ref<KeyT>, values: {
|
|
169
|
-
[fieldName: string]: any;
|
|
170
|
-
}): void;
|
|
171
|
-
/**
|
|
172
|
-
* Resets the mock store
|
|
173
|
-
*/
|
|
174
|
-
reset(): void;
|
|
175
|
-
}
|
|
176
|
-
export declare type Ref<KeyT extends KeyTypeConstraints = string> = {
|
|
177
|
-
$ref: {
|
|
178
|
-
key: KeyT;
|
|
179
|
-
typeName: string;
|
|
180
|
-
};
|
|
181
|
-
};
|
|
182
|
-
export declare function isRef<KeyT extends KeyTypeConstraints = string>(maybeRef: unknown): maybeRef is Ref<KeyT>;
|
|
183
|
-
export declare function assertIsRef<KeyT extends KeyTypeConstraints = string>(maybeRef: unknown, message?: string): asserts maybeRef is Ref<KeyT>;
|
|
184
|
-
export declare function isRecord(obj: unknown): obj is {
|
|
185
|
-
[key: string]: unknown;
|
|
186
|
-
};
|
|
187
|
-
export interface IMockServer {
|
|
188
|
-
/**
|
|
189
|
-
* Executes the provided query against the mocked schema.
|
|
190
|
-
* @param query GraphQL query to execute
|
|
191
|
-
* @param vars Variables
|
|
192
|
-
*/
|
|
193
|
-
query: (query: string, vars?: Record<string, any>) => Promise<ExecutionResult>;
|
|
194
|
-
}
|
package/es5/utils.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Ref, KeyTypeConstraints } from './types';
|
|
2
|
-
export declare function uuidv4(): string;
|
|
3
|
-
export declare const randomListLength: () => number;
|
|
4
|
-
export declare const takeRandom: <T>(arr: T[]) => T;
|
|
5
|
-
export declare function makeRef<KeyT extends KeyTypeConstraints = string>(typeName: string, key: KeyT): Ref<KeyT>;
|
|
6
|
-
export declare function isObject(thing: any): boolean;
|
|
7
|
-
export declare function copyOwnPropsIfNotPresent(target: Record<string, any>, source: Record<string, any>): void;
|
|
8
|
-
export declare function copyOwnProps(target: Record<string, any>, ...sources: Array<Record<string, any>>): Record<string, any>;
|