apollographql / apollographql/graphql-testing-library

Code feedback

Open
#44 4 comments 3 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
61
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Hey! So excited to finally see this library out!

I will provide a few code review and suggestions below. Feel free to convert this to a discussion or whichever format is more suitable for you.

https://github.com/apollographql/graphql-testing-library/blob/e18caf4ef4b3133b438500bafebdf127e4189417/src/handlers.ts#L92-L94

This isn't something MSW can solve with the current version range of TS we support, unfortunately. You can learn more about why here: https://github.com/mswjs/msw/issues/1691.

_Solution:_ Provide a _union_ of expected response types to the handler. I'm not sure if `graphql.*()` functions support that right now though. It [looks](https://github.com/mswjs/msw/blob/bed402cdd9b79ef3084b3195cdcce0d83c7e2cfc/src/core/graphql.ts#L47) like they infer the response resolver (and its return type) from the query. Let me know if this turns problematic, we can work on a solution for it.

---

https://github.com/apollographql/graphql-testing-library/blob/e18caf4ef4b3133b438500bafebdf127e4189417/src/handlers.ts#L163-L164

It would be great to let the folks use the built-in [delay values](https://mswjs.io/docs/api/delay) too, like `infinite` or random server response time. Looks like a change [here](https://github.com/apollographql/graphql-testing-library/blob/e18caf4ef4b3133b438500bafebdf127e4189417/src/handlers.ts#L40).

---

For debugging reasons, it would be nice to see what schema was used when a handler was run. You can achieve that by creating a [_custom request handler_](https://mswjs.io/docs/api/request-handler) instead of wrapping `graphql.operation()`. You can then define its `log()` method to include the schema when debugging handlers.

I think that can be handy given you can swap the schema mid-test. You also get access to internal caching API which you can use to cache any computation you need (like `gql(query)` or AST parsing, if that makes sense).

---

If you have any questions about the WebSocket mocking, please let me know.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with src/handlers.ts at lines 40, 92-94, and 163-164, then read the linked MSW TypeScript, delay, request-handler, and graphql.operation references. The issue bundles response typing, delay values, and schema logging, so first establish which proposals are accepted and whether they fit the current APIs. Done requires an agreed scope and corresponding handler behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.