dotansimha / dotansimha/graphql-code-generator-community

msw plugin does not allow to pass `RequestHandlerOptions` on generated mocks

Open
#563 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

**Is your feature request related to a problem? Please describe.**

msw plugin does not allow to pass `RequestHandlerOptions` on generated mocks

**Describe the solution you'd like**

The mocks should include the optional 3rd parameter `RequestHandlerOptions` which would enable us to provide `once` https://mswjs.io/docs/api/graphql#once (v2 API)

Example of the current generated mock
```typescript
/**
* @param resolver a function that accepts a captured request and may return a mocked response.
* @see https://mswjs.io/docs/basics/response-resolver
* @example
* mockWhateverQuery((req, res, ctx) => {
* const { property1, property2 } = req.variables;
* return res(
* ctx.data({ property1, property })
* )
* })
*/
export const mockWhateverQuery = (resolver: Parameters>[1]) =>
graphql.query(
'whatever',
resolver
)

```

Proposal

```typescript
/**
* @param resolver a function that accepts a captured request and may return a mocked response.
* @param options object that if `once` is set to true, marks this request handler as used after the first successful match. Used request handlers have no effect on the outgoing traffic and will be ignored during request interception.
* @see https://mswjs.io/docs/basics/response-resolver
* @example
* mockWhateverQuery((req, res, ctx) => {
* const { property1, property2 } = req.variables;
* return res(
* ctx.data({ property1, property })
* )
* })
*/
export const mockWhateverQuery = (resolver: Parameters>[1]) =>
graphql.query(
'whatever',
resolver,
options // <-- Notice this is a valid optional object where we could provide `once`
)

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.