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

How to intercept Graphql request? #110

Open
ThiagoMFerreira opened this issue Oct 16, 2020 · 7 comments
Open

How to intercept Graphql request? #110

ThiagoMFerreira opened this issue Oct 16, 2020 · 7 comments

Comments

@ThiagoMFerreira
Copy link

Hello,
I need to intercept Grahpql requests to my tests, but this is fetch type, so the Intercept service isn't getting the request, is there any way to intercept this request?

the request is returning the result of this way
data: {values: {totalPages: 10,…}},…} data: {values: {totalPages: 10,…}} values: {totalPages: 10,…}

Thank You.

@ruancarvalho
Copy link

Hey @ThiagoMFerreira, did you had any progress with this kind of tests?
I believe I'm having the same issues.

It doesn't catch graphql requests, although they're shown in the network tab.

@ThiagoMFerreira
Copy link
Author

Hey @ThiagoMFerreira, did you had any progress with this kind of tests?
I believe I'm having the same issues.

It doesn't catch graphql requests, although they're shown in the network tab.

Hi @ruancarvalho any progress yet 😔

@chmanie
Copy link
Member

chmanie commented Mar 31, 2021

GraphQL requests are not particularly special. This plugin has been supporting fetch since v3 (https://github.com/chmanie/wdio-intercept-service/blob/master/CHANGELOG.md#---300--13022019).
Have you noticed this:

There's one catch though: you can't intercept HTTP calls that are initiated on page load (like in most SPAs), as it requires some setup work that can only be done after the page is loaded (due to limitations in selenium). That means you can just capture requests that were initiated inside a test.

@andreluisce
Copy link

Hey @chmanie Even though my requests happens inside my test, it does not capture the Grapqh requests. Do you have any thoughts about it?

@tehhowch
Copy link
Contributor

@andreluisce are the requests issued from an iframe?

@trietnguyen267
Copy link

I had same problem when trying intercepting graphql request which it would return JSON data. it seems interceptor didnt recognised the requests as ajax calls at all

@PeterPimentel
Copy link

@trietnguyen267 I had the same problem.
Solved it using the mock function https://webdriver.io/docs/mocksandspies/#spies

You are able to mock the graphql requests and then create a helper function to validate what you want based on the operationName.

const mocks = await browser.mock('**/graphql', { method: 'post' })

console.log(mock.calls[0].postData)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants