easygraphql-tester icon indicating copy to clipboard operation
easygraphql-tester copied to clipboard

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

Open fernandohenriques opened this issue 6 years ago • 1 comments

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
 / / {}

fernandohenriques avatar Jul 15 '19 13:07 fernandohenriques

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

estrada9166 avatar Jul 16 '19 00:07 estrada9166