Skip to content
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

Adds a "graphql.link" API #319

Merged
merged 3 commits into from
Aug 5, 2020
Merged

Adds a "graphql.link" API #319

merged 3 commits into from
Aug 5, 2020

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Aug 4, 2020

Changes

  • Isolates request matching logic (resolved/clean mask, match) into its own utility.
  • Exposes matchRequestUrl in the public API:
import { matchRequestUrl } from 'msw'

matchRequestUrl(req.url, '*/your/mask')

This would allow developers to create custom request handlers (#290) with the native MSW request matching logic embedded.

  • Request matching is now performed in the "parse" phase for rest. This allows us to match request URL against a mask once, so we don't have to do this again to get request params later on.
  • Reuses the request matching utility for rest and graphql API.
  • Adds graphql.link API that allows to define per-endpoint GraphQL operations mocking.
import { graphql } from 'msw'

const github = graphql.link('https://api.github.com/graphql')
const stripe = graphql.link('https://api.stripe.com/graphql')

github.query('GetUser', resolver)
stripe.mutation('Payment', resolver)

GitHub

@kettanaito
Copy link
Member Author

@chrisguttandin, hey, Chris! Please, do you have a chance to review these changes? Your feedback would be highly appreciated. Thanks!

Copy link
Member

@marcosvega91 marcosvega91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chrisguttandin
Copy link
Collaborator

Hi @kettanaito, was that maybe a mistake to ping me? I'm happy to take a look but I'm not GraphQL user and therefore can't really give any meaningful feedback.

@kettanaito
Copy link
Member Author

@chrisguttandin, it's okay, these changes are not related to the actual GraphQL knowledge :) If you have a minute, I'd appreciate you to look as well.

@marcosvega91, thank you for the review!

@kettanaito
Copy link
Member Author

If you don't mind, I'm merging this, would love to ship this to hear people's feedback.

@kettanaito kettanaito merged commit 25eeeff into master Aug 5, 2020
@kettanaito kettanaito deleted the 315-graphql-link branch August 5, 2020 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support multiple GraphQL endpoints
3 participants