-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract and expose mockLink
helper functions normalizeMockedResponse
and requestToKey
#12138
Extract and expose mockLink
helper functions normalizeMockedResponse
and requestToKey
#12138
Conversation
`normalizeMockedResponse` and `requestToKey` are useful for creating custom mock links that are compatible with the existing `MockedResponse` architecture. So the methods are now both exported functions.
@destin-estrela: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
👷 Deploy request for apollo-client-docs pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: a8c13ce The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Docs Preview ReadyNo new or changed pages found. |
I'll discuss this with the team later That said, I'll already add a few loose thoughts here - this is not a final decision, but meant to give you some insights - comments are very welcome :)
All that said, I'm slightly negative towards exposing more internals here, but I could easily be swayed. Let's see what our discussion later brings up :) |
Would absolutely love to give your use case a try! Please share it in mswjs/msw#2352. MSW + GraphQL Testing Library is the way to go with testing GraphQL APIs. |
@phryneas @kettanaito Thank you for your insights! So far we've been quite comfortable using the traditional I'll look into how our team can transition to MSW + GraphQL Testing Library to ergonomically accomplish the same thing moving forward. @phryneas I'll assume based on your comments that In which case, should I close this PR? |
As you seem to have a workaround in place for now by copy-pasting this, yes, I think it might make sense to close the PR. That said, kudos for digging into this and opening a PR - generally, it's very welcome! |
Appreciate the warm welcome! Closing this based on our discussions above. |
Overview
normalizeMockedResponse
andrequestToKey
were both useful for creating a customApolloLink
that's compatible with the existingMockedResponse
type. So I moved these methods into their own functions and exported them so they can be reused.This is exposing more implementation details that will then need to be maintained. So let me know if this is acceptable or not. I can also add detailed documentation if we decide to move forward with this.
More specifically, I implemented a custom link called
TestSubscriptionLink
that, like the internal (?)MockSubscriptionLink
, allows controlling subscriptions in tests. But it's higher fidelity and acts as an inverse of theMockLink
. It allows pushing aMockedResponse
to specific subscriptions using the same request and variable matching logic ofmockLink.ts
.Example In Custom
ApolloLink
PS, please consider supporting something like this officially, there's been a few posts on the web here and there asking about it in the last couple of years :).