EasyGraphQL / easygraphql-tester

Test GraphQL queries, mutations and schemas on an easy way! 🚀
https://easygraphql.com/docs/easygraphql-tester/overview
MIT License
313 stars 34 forks source link

How to use test.mock if result is a Union type #117

Open fernandohenriques opened 5 years ago

fernandohenriques commented 5 years ago

In this example in my code, the query returns always empty:

 it('Should return store by id', () => {
    const query = `
      query($id: ID, $slug: String) {
        store(id: $id, slug: $slug) {
          ... on Store {
            id
            name
            slug
          }
        }
      }
    `;

    const fixture = {
      data: {
        store: {
          id: '1',
          name: 'AnyoneStore'
        }
      }
    };

    const variables = {
      id: "1"
    };

    const { data: { store } } = tester.mock({ query, fixture, variables });

   // store
  / / {}
estrada9166 commented 5 years ago

Can you share your schema please, so I can reproduce it locally?

As you can see here it should be working fine for unions.

Also, you can use this codesandbox template to reproduce the test, and we can test it there