Skip to content

Commit 362bc4a

Browse files
committed
no mocking
1 parent 0f0ec52 commit 362bc4a

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

packages/web/docs/src/content/gateway/other-features/testing/mocking.mdx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ import { Callout } from '@theguild/components'
99
Mocking your GraphQL API is a common practice when developing and testing your application. It
1010
allows you to simulate the behavior of your API without making real network requests.
1111

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+
1220
## How to use?
1321

1422
Add it to your plugins:
1523

1624
```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'
1827

1928
export const gatewayConfig = defineConfig({
2029
plugins: [
@@ -38,7 +47,8 @@ The example above will replace the resolver of `User.firstName` with a mock that
3847
You can also provide a custom function to generate the mock value for a field:
3948

4049
```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'
4252
import { fullName } from './user-mocks.js'
4353

4454
export const gatewayConfig = defineConfig({
@@ -60,7 +70,8 @@ export const gatewayConfig = defineConfig({
6070
You can mock types with custom mock functions like below;
6171

6272
```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'
6475
import { user } from './user-mocks.js'
6576

6677
export const gatewayConfig = defineConfig({
@@ -116,7 +127,8 @@ type User {
116127
```
117128

118129
```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'
120132

121133
export const gatewayConfig = defineConfig({
122134
plugins: pluginCtx => [
@@ -160,7 +172,7 @@ using the store provided in the context `context.mockStore`;
160172
When having a schema that returns a list, in this case, a list of users:
161173

162174
```ts filename="init-store.ts"
163-
import { MockStore } from '@graphql-hive/gateway'
175+
import { MockStore } from '@graphql-mesh/plugin-mock'
164176

165177
export const store = new MockStore()
166178
const users = [{ id: 'uuid', name: 'John Snow' }]
@@ -184,7 +196,8 @@ type Query {
184196
```
185197

186198
```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'
188201
import { store } from './init-store.js'
189202

190203
export const gatewayConfig = defineConfig({
@@ -219,7 +232,8 @@ type Mutation {
219232
```
220233

221234
```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'
223237
import { store } from './init-store.js'
224238

225239
export const gatewayConfig = defineConfig({

packages/web/docs/src/content/migration-guides/gateway-v1-v2.mdx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ instructions to ensure a smooth transition.
99
v2 includes several breaking changes and improvements over v1. The most significant changes are:
1010

1111
- [Drop Support for Node v18](#drop-support-for-node-v18)
12-
- [Multipart Requests are Disabled by Default](#drop-support-for-node-v18)
12+
- [Multipart Requests are Disabled by Default](#multipart-requests-are-disabled-by-default)
13+
- [Remove Mocking Plugin from built-ins](#remove-mocking-plugin-from-built-ins)
1314
- [Disabled Automatic Forking](#disabled-automatic-forking)
1415
- [New Hive Logger for next-level observability and debugging](#hive-logger)
1516

@@ -65,6 +66,44 @@ export const gatewayConfig = defineConfig({
6566
});
6667
```
6768

69+
# Remove Mocking Plugin from built-ins
70+
71+
There is no need to provide the `useMock` plugin alongside Hive Gateway built-ins. Not only is the
72+
mock plugin 2MB in size (minified), but installing and using it is very simple.
73+
74+
Migrating is very simple, start by installing the `@graphql-mesh/plugin-mock` package:
75+
76+
```sh npm2yarn
77+
npm i @graphql-mesh/plugin-mock
78+
```
79+
80+
and then use it in your Hive Gateway configuration:
81+
82+
```diff filename="gateway.config.ts"
83+
import {
84+
defineConfig,
85+
- useMock
86+
} from '@graphql-hive/gateway';
87+
+ import { useMock } from '@graphql-mesh/plugin-mock'
88+
89+
export const gatewayConfig = defineConfig({
90+
plugins: [
91+
useMock({
92+
mocks: [
93+
{
94+
apply: 'User.firstName',
95+
faker: '{{name.firstName}}'
96+
}
97+
]
98+
})
99+
]
100+
})
101+
```
102+
103+
<Callout type="info">
104+
You can read more about the mocking plugin in the [Mocking documentation](/docs/gateway/mocking).
105+
</Callout>
106+
68107
## Disabled Automatic Forking
69108

70109
We were previously forking workers automatically in v1 when detecting `NODE_ENV=production`;

0 commit comments

Comments
 (0)