@@ -9,12 +9,21 @@ import { Callout } from '@theguild/components'
9
9
Mocking your GraphQL API is a common practice when developing and testing your application. It
10
10
allows you to simulate the behavior of your API without making real network requests.
11
11
12
+ ## Installing
13
+
14
+ Start by installing the ` @graphql-mesh/plugin-mock ` package:
15
+
16
+ ``` sh npm2yarn
17
+ npm i @graphql-mesh/plugin-mock
18
+ ```
19
+
12
20
## How to use?
13
21
14
22
Add it to your plugins:
15
23
16
24
``` ts filename="gateway.config.ts"
17
- import { defineConfig , useMock } from ' @graphql-hive/gateway'
25
+ import { defineConfig } from ' @graphql-hive/gateway'
26
+ import { useMock } from ' @graphql-mesh/plugin-mock'
18
27
19
28
export const gatewayConfig = defineConfig ({
20
29
plugins: [
@@ -38,7 +47,8 @@ The example above will replace the resolver of `User.firstName` with a mock that
38
47
You can also provide a custom function to generate the mock value for a field:
39
48
40
49
``` ts filename="gateway.config.ts"
41
- import { defineConfig , useMock } from ' @graphql-hive/gateway'
50
+ import { defineConfig } from ' @graphql-hive/gateway'
51
+ import { useMock } from ' @graphql-mesh/plugin-mock'
42
52
import { fullName } from ' ./user-mocks.js'
43
53
44
54
export const gatewayConfig = defineConfig ({
@@ -60,7 +70,8 @@ export const gatewayConfig = defineConfig({
60
70
You can mock types with custom mock functions like below;
61
71
62
72
``` ts filename="gateway.config.ts"
63
- import { defineConfig , useMock } from ' @graphql-hive/gateway'
73
+ import { defineConfig } from ' @graphql-hive/gateway'
74
+ import { useMock } from ' @graphql-mesh/plugin-mock'
64
75
import { user } from ' ./user-mocks.js'
65
76
66
77
export const gatewayConfig = defineConfig ({
@@ -116,7 +127,8 @@ type User {
116
127
```
117
128
118
129
```ts filename ="gateway.config.ts"
119
- import { defineConfig , useMock } from '@graphql -hive /gateway '
130
+ import { defineConfig } from '@graphql -hive /gateway '
131
+ import { useMock } from '@graphql -mesh /plugin -mock '
120
132
121
133
export const gatewayConfig = defineConfig ({
122
134
plugins : pluginCtx => [
@@ -160,7 +172,7 @@ using the store provided in the context `context.mockStore`;
160
172
When having a schema that returns a list, in this case, a list of users:
161
173
162
174
``` ts filename="init-store.ts"
163
- import { MockStore } from ' @graphql-hive/gateway '
175
+ import { MockStore } from ' @graphql-mesh/plugin-mock '
164
176
165
177
export const store = new MockStore ()
166
178
const users = [{ id: ' uuid' , name: ' John Snow' }]
@@ -184,7 +196,8 @@ type Query {
184
196
```
185
197
186
198
```ts filename ="gateway.config.ts"
187
- import { defineConfig , useMock } from '@graphql -hive /gateway '
199
+ import { defineConfig } from '@graphql -hive /gateway '
200
+ import { useMock } from '@graphql -mesh /plugin -mock '
188
201
import { store } from './init -store .js '
189
202
190
203
export const gatewayConfig = defineConfig ({
@@ -219,7 +232,8 @@ type Mutation {
219
232
```
220
233
221
234
```ts filename ="gateway.config.ts"
222
- import { defineConfig , useMock } from '@graphql -hive /gateway '
235
+ import { defineConfig } from '@graphql -hive /gateway '
236
+ import { useMock } from '@graphql -mesh /plugin -mock '
223
237
import { store } from './init -store .js '
224
238
225
239
export const gatewayConfig = defineConfig ({
0 commit comments