Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
at main 52 lines 917 B view raw
1import type { GraphQLRequest, OperationContext, Operation } from '@urql/core'; 2import { gql, makeOperation } from '@urql/core'; 3 4const context: OperationContext = { 5 fetchOptions: { 6 method: 'POST', 7 }, 8 requestPolicy: 'cache-first', 9 url: 'http://localhost:3000/graphql', 10}; 11 12const queryGql: GraphQLRequest = { 13 key: 2, 14 query: gql` 15 query getUser($name: String) { 16 user(name: $name) { 17 id 18 firstName 19 lastName 20 } 21 } 22 `, 23 variables: { 24 name: 'Clara', 25 }, 26}; 27 28export const mutationGql: GraphQLRequest = { 29 key: 2, 30 query: gql` 31 mutation AddUser($name: String) { 32 addUser(name: $name) { 33 name 34 } 35 } 36 `, 37 variables: { 38 name: 'Clara', 39 }, 40}; 41 42export const queryOperation: Operation = makeOperation( 43 'query', 44 queryGql, 45 context 46); 47 48export const mutationOperation: Operation = makeOperation( 49 'mutation', 50 mutationGql, 51 context 52);