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

Waiting for an intercepted graphql request yields the request/response of a prior request #30507

Open
betawind opened this issue Oct 31, 2024 · 1 comment
Labels
stage: needs investigating Someone from Cypress needs to look at this

Comments

@betawind
Copy link

betawind commented Oct 31, 2024

Current behavior

I'm using the pattern defined below to intercept and assert on graphql requests and responses:
https://docs.cypress.io/app/guides/network-requests#Alias-multiple-queries-or-mutations

The test runs the cy.intercept in a beforeEach, and includes a single aliasQuery call in the route handler function.

The page uses Graphql to populate data in a table, and interacting with the page results in additional requests to Graphql for new data. When using cy.wait on a request that occurs after several have already occurred, the resultant request object is for a prior request. I can use cy.wait multiple times to get each request's details sequentially.

Example

  1. Before the page loads I use cy.intercept to create an alias for the getData Graphql operation called gqlGetDataQuery
  2. Page loads, Graphql operation getData is called
  3. Make a change on the page that triggers a new request to Graphql operation getData
  4. Make another change on the page that triggers a new request to Graphql operation getData
  5. cy.wait('gqlGetDataQuery') results in the data for step 2
  6. another call to cy.wait('gqlGetDataQuery') results in the data for step 3
  7. cy.wait('gqlGetDataQuery') results in the data for step 4###

Desired behavior

cy.wait returns the request/response for the most recent Graphql query

Test code to reproduce

NOTE: The test code uses Cypress Dashboard and it's Graphql endpoint to demonstrate the issue. To run this you'll need to do the following:

  1. Log in to Cypress Dashboard
  2. Copy the "cy_dashboard" cookie using developer tools and update the "cyDashboardCookie" variable below
  3. Select a project to run this, copy the projectId from the URL, and update the "projectId" variable below

REPO WITH THE ISSUE: https://github.com/betawind/cypress-30507

Cypress Version

13.15.1

Node version

v20.17.0

Operating System

macOS 15.1

Debug Logs

No response

Other

No response

@jennifer-shehane jennifer-shehane added the stage: needs investigating Someone from Cypress needs to look at this label Nov 5, 2024
@Tzinov15
Copy link

Tzinov15 commented Nov 6, 2024

I believe we may be hitting something similar with this, so commenting mainly to follow development, but what we're seeing is an apparent issue where cy.wait(queryAlias.all) will return the correct number of intercepted requests (4) when we send back a stub in the response (ie: req.reply()) but will for some reason respond with 6 when we don't send back a stub and allow the request to pass through to the server

attached is the result of calling cy.get('${alias}.all')

Screenshot 2024-11-05 at 6 22 07 PM

Potentially related to the problem, I am seeing redundant ids with "interceptedRequest562" and "interceptedRequest597" showing up twice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs investigating Someone from Cypress needs to look at this
Projects
None yet
Development

No branches or pull requests

3 participants