1 |
|
2 |
|
3 |
|
4 | import 'whatwg-fetch';
|
5 | import { GraphQLResult, Document } from 'graphql';
|
6 | import { MiddlewareInterface } from './middleware';
|
7 | import { AfterwareInterface } from './afterware';
|
8 | export interface Request {
|
9 | debugName?: string;
|
10 | query?: Document;
|
11 | variables?: Object;
|
12 | operationName?: string;
|
13 | [additionalKey: string]: any;
|
14 | }
|
15 | export interface PrintedRequest {
|
16 | debugName?: string;
|
17 | query?: string;
|
18 | variables?: Object;
|
19 | operationName?: string;
|
20 | }
|
21 | export interface NetworkInterface {
|
22 | [others: string]: any;
|
23 | query(request: Request): Promise<GraphQLResult>;
|
24 | }
|
25 | export interface SubscriptionNetworkInterface extends NetworkInterface {
|
26 | subscribe(request: Request, handler: (error: any, result: any) => void): number;
|
27 | unsubscribe(id: Number): void;
|
28 | }
|
29 | export interface BatchedNetworkInterface extends NetworkInterface {
|
30 | batchQuery(requests: Request[]): Promise<GraphQLResult[]>;
|
31 | }
|
32 | export interface HTTPNetworkInterface extends BatchedNetworkInterface {
|
33 | _uri: string;
|
34 | _opts: RequestInit;
|
35 | _middlewares: MiddlewareInterface[];
|
36 | _afterwares: AfterwareInterface[];
|
37 | use(middlewares: MiddlewareInterface[]): any;
|
38 | useAfter(afterwares: AfterwareInterface[]): any;
|
39 | }
|
40 | export interface RequestAndOptions {
|
41 | request: Request;
|
42 | options: RequestInit;
|
43 | }
|
44 | export interface ResponseAndOptions {
|
45 | response: IResponse;
|
46 | options: RequestInit;
|
47 | }
|
48 | export declare function addQueryMerging(networkInterface: NetworkInterface): BatchedNetworkInterface;
|
49 | export declare function printRequest(request: Request): PrintedRequest;
|
50 | export declare class HTTPFetchNetworkInterface implements NetworkInterface {
|
51 | _uri: string;
|
52 | _opts: RequestInit;
|
53 | _middlewares: MiddlewareInterface[];
|
54 | _afterwares: AfterwareInterface[];
|
55 | constructor(uri: string, opts?: RequestInit);
|
56 | applyMiddlewares({request, options}: RequestAndOptions): Promise<RequestAndOptions>;
|
57 | applyAfterwares({response, options}: ResponseAndOptions): Promise<ResponseAndOptions>;
|
58 | fetchFromRemoteEndpoint({request, options}: RequestAndOptions): Promise<IResponse>;
|
59 | query(request: Request): Promise<GraphQLResult>;
|
60 | use(middlewares: MiddlewareInterface[]): void;
|
61 | useAfter(afterwares: AfterwareInterface[]): void;
|
62 | }
|
63 | export interface NetworkInterfaceOptions {
|
64 | uri: string;
|
65 | opts?: RequestInit;
|
66 | transportBatching?: boolean;
|
67 | }
|
68 | export declare function createNetworkInterface(interfaceOpts: (NetworkInterfaceOptions | string), backOpts?: RequestInit): HTTPNetworkInterface;
|