-
-
Notifications
You must be signed in to change notification settings - Fork 459
/
types.ts
58 lines (47 loc) · 1.96 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Source } from 'wonka';
import { Client } from './client';
import { CombinedError } from './utils/error';
export { ExecutionResult } from 'graphql';
/** The type of GraphQL operation being executed. */
export type OperationType = 'subscription' | 'query' | 'mutation' | 'teardown';
/** A Graphql query, mutation, or subscription. */
export interface GraphQLRequest {
query: string;
variables?: object;
}
export type GraphqlQuery = GraphQLRequest;
export type GraphqlMutation = GraphQLRequest;
export type GraphqlSubscription = GraphQLRequest;
/** Additional metadata passed to [exchange]{@link Exchange} functions. */
export interface OperationContext {
[key: string]: any;
fetchOptions?: RequestInit;
url: string;
}
/** A [query]{@link Query} or [mutation]{@link Mutation} with additional metadata for use during transmission. */
export interface Operation extends GraphQLRequest {
/** Unique identifier of the operation. */
key: string;
operationName: OperationType;
context: OperationContext;
}
/** Resulting data from an [operation]{@link Operation}. */
export interface OperationResult {
/** The [operation]{@link Operation} which has been executed. */
operation: Operation;
/** The data returned from the Graphql server. */
data?: any;
/** Any errors resulting from the operation. */
error?: CombinedError;
}
/** Input parameters for to an Exchange factory function. */
export interface ExchangeInput {
forward: ExchangeIO;
client: Client;
}
/** Function responsible for listening for streamed [operations]{@link Operation}. */
export type Exchange = (input: ExchangeInput) => ExchangeIO;
/** Function responsible for receiving an observable [operation]{@link Operation} and returning a [result]{@link OperationResult}. */
export type ExchangeIO = (ops$: Source<Operation>) => Source<OperationResult>;
// /** The arguments for the child function of a connector. */
// export type ChildArgs<MutationDeclarations> = ClientState<MutationDeclarations>;