1import { gql } from '../gql';
2
3import type {
4 ExecutionResult,
5 GraphQLRequest,
6 Operation,
7 OperationContext,
8 OperationResult,
9} from '../types';
10import { makeOperation } from '../utils';
11
12export const context: OperationContext = {
13 fetchOptions: {
14 method: 'POST',
15 },
16 requestPolicy: 'cache-first',
17 url: 'http://localhost:3000/graphql',
18};
19
20export const queryGql: GraphQLRequest = {
21 key: 2,
22 query: gql`
23 query getUser($name: String) {
24 user(name: $name) {
25 id
26 firstName
27 lastName
28 }
29 }
30 `,
31 variables: {
32 name: 'Clara',
33 },
34};
35
36export const mutationGql: GraphQLRequest = {
37 key: 3,
38 query: gql`
39 mutation AddUser($name: String) {
40 addUser(name: $name) {
41 name
42 }
43 }
44 `,
45 variables: {
46 name: 'Clara',
47 },
48};
49
50export const subscriptionGql: GraphQLRequest = {
51 key: 4,
52 query: gql`
53 subscription subscribeToUser($user: String) {
54 user(user: $user) {
55 name
56 }
57 }
58 `,
59 variables: {
60 user: 'colin',
61 },
62};
63
64export const queryOperation: Operation = makeOperation(
65 'query',
66 {
67 query: queryGql.query,
68 variables: queryGql.variables,
69 key: queryGql.key,
70 },
71 context
72);
73
74export const teardownOperation: Operation = makeOperation(
75 'teardown',
76 {
77 query: queryOperation.query,
78 variables: queryOperation.variables,
79 key: queryOperation.key,
80 },
81 context
82);
83
84export const mutationOperation: Operation = makeOperation(
85 'mutation',
86 {
87 query: mutationGql.query,
88 variables: mutationGql.variables,
89 key: mutationGql.key,
90 },
91 context
92);
93
94export const subscriptionOperation: Operation = makeOperation(
95 'subscription',
96 {
97 query: subscriptionGql.query,
98 variables: subscriptionGql.variables,
99 key: subscriptionGql.key,
100 },
101 context
102);
103
104export const undefinedQueryResponse: OperationResult = {
105 operation: queryOperation,
106 stale: false,
107 hasNext: false,
108};
109
110export const queryResponse: OperationResult = {
111 operation: queryOperation,
112 data: {
113 user: {
114 name: 'Clive',
115 },
116 },
117 stale: false,
118 hasNext: false,
119};
120
121export const mutationResponse: OperationResult = {
122 operation: mutationOperation,
123 data: {},
124 stale: false,
125 hasNext: false,
126};
127
128export const subscriptionResult: ExecutionResult = {
129 data: {},
130};