Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
at main 1.0 kB view raw
1import { gql } from '@urql/core'; 2import { it, afterEach, expect } from 'vitest'; 3import { __initAnd_query as query } from '../operations/query'; 4import { __initAnd_write as write } from '../operations/write'; 5import { Store } from '../store/store'; 6 7afterEach(() => { 8 expect(console.warn).not.toHaveBeenCalled(); 9}); 10 11it('allows viewer fields to overwrite the root Query data', () => { 12 const store = new Store(); 13 const get = gql` 14 { 15 int 16 } 17 `; 18 const set = gql` 19 mutation { 20 mutate { 21 viewer { 22 int 23 } 24 } 25 } 26 `; 27 28 write( 29 store, 30 { query: get }, 31 { 32 __typename: 'Query', 33 int: 42, 34 } 35 ); 36 37 write( 38 store, 39 { query: set }, 40 { 41 __typename: 'Mutation', 42 mutate: { 43 __typename: 'MutateResult', 44 viewer: { 45 __typename: 'Query', 46 int: 43, 47 }, 48 }, 49 } 50 ); 51 52 const res = query(store, { query: get }); 53 54 expect(res.partial).toBe(false); 55 expect(res.data).toEqual({ 56 int: 43, 57 }); 58});