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

Mock data always return "Hello World" #37

Open
gmoura opened this issue Apr 22, 2020 · 3 comments
Open

Mock data always return "Hello World" #37

gmoura opened this issue Apr 22, 2020 · 3 comments

Comments

@gmoura
Copy link

gmoura commented Apr 22, 2020

Hi guys, I'm quite new in GraphQL world and currently I'm facing some difficulties/trouble trying to implement this plugin, If anyone can help, I'll be really thankful .

Problem:

All my mock data fields are returning Hello World

How I'm using this plugin:

In my integration/index.spec.js

  context('Get email', () => {
      beforeEach(() => {
          cy.server();
          cy.mockGraphql({ schema });
          cy.mockGraphqlOps({
              operations: {
                GetEmail: {
                  email: "[email protected]",
                }
              }
          })
      });
      
        it('Should mock graphql', () => {
          cy.visit('/')
        })
  })

But I get

{
  GetEmail: {
    email: 'Hello World'
  }
}

Thanks guys ❤️

@jfairley
Copy link

@gmoura responding with "Hello World" is actually some default functionality in Apollo Server. I was just having this issue, too. For me, the real issue was that cypress-graphql-mock wasn't configured correctly. Also make sure your object structure in cy.mockGraphqlOps matches the request you're making.

@sarink
Copy link

sarink commented May 13, 2020

Can @jfairley / anyone elaborate? In what way is the OP's code configured incorrectly?

@jfairley
Copy link

jfairley commented May 13, 2020

@sarink

Since it's an API mock, it could be a number of things, but would depend on the larger context of @gmoura's app.

The big takeaway is that it seems that cypress-graphql-mock is actually intercepting the request, because apollo-server is responding, but something about the cy.mockGraphqlOps probably doesn't match the request that's sent out.

If I had to guess, it looks like @gmoura is missing a level in that structure.

For example, I have a mocked request in my app like this:

      cy.mockGraphqlOps({
        operations: {
          Partner: {
            partnersRates: [
              /* data */

which corresponds to

export const HIERARCHIES = gql`
  query Partner($parentId: Float!) {
    partnersRates(parentId: $parentId) {

In this case, partnersRates is the graphql operation as defined on the server, while Partner is simply how I named the query on the client via query Partner.

Sometimes these names are the same, but that's why I say "it depends".

Possibly, what @gmoura needs is the following, but it's impossible to know without seeing the source query in the client code.

          cy.mockGraphqlOps({
              operations: {
                GetEmail: {
                  GetEmail: {
                    email: "[email protected]",
                  }
                }
              }
          })

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

No branches or pull requests

3 participants