UNPKG

2.62 kBTypeScriptView Raw
1/// <reference types="typed-graphql" />
2/// <reference types="chai" />
3/// <reference types="isomorphic-fetch" />
4import 'whatwg-fetch';
5import { GraphQLResult, Document } from 'graphql';
6import { MiddlewareInterface } from './middleware';
7import { AfterwareInterface } from './afterware';
8export interface Request {
9 debugName?: string;
10 query?: Document;
11 variables?: Object;
12 operationName?: string;
13 [additionalKey: string]: any;
14}
15export interface PrintedRequest {
16 debugName?: string;
17 query?: string;
18 variables?: Object;
19 operationName?: string;
20}
21export interface NetworkInterface {
22 [others: string]: any;
23 query(request: Request): Promise<GraphQLResult>;
24}
25export interface SubscriptionNetworkInterface extends NetworkInterface {
26 subscribe(request: Request, handler: (error: any, result: any) => void): number;
27 unsubscribe(id: Number): void;
28}
29export interface BatchedNetworkInterface extends NetworkInterface {
30 batchQuery(requests: Request[]): Promise<GraphQLResult[]>;
31}
32export 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}
40export interface RequestAndOptions {
41 request: Request;
42 options: RequestInit;
43}
44export interface ResponseAndOptions {
45 response: IResponse;
46 options: RequestInit;
47}
48export declare function addQueryMerging(networkInterface: NetworkInterface): BatchedNetworkInterface;
49export declare function printRequest(request: Request): PrintedRequest;
50export 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}
63export interface NetworkInterfaceOptions {
64 uri: string;
65 opts?: RequestInit;
66 transportBatching?: boolean;
67}
68export declare function createNetworkInterface(interfaceOpts: (NetworkInterfaceOptions | string), backOpts?: RequestInit): HTTPNetworkInterface;