UNPKG

2.87 kBTypeScriptView Raw
1import { IntrospectionOptions } from 'graphql';
2import { SchemaPointerSingle, Source, DocumentLoader, SingleFileOptions } from '@graphql-tools/utils';
3import { fetch as crossFetch } from 'cross-fetch';
4import { AsyncExecutor, Subscriber } from '@graphql-tools/delegate';
5import { w3cwebsocket } from 'websocket';
6export declare type FetchFn = typeof import('cross-fetch').fetch;
7declare type Headers = Record<string, string> | Array<Record<string, string>>;
8/**
9 * Additional options for loading from a URL
10 */
11export interface LoadFromUrlOptions extends SingleFileOptions, Partial<IntrospectionOptions> {
12 /**
13 * Additional headers to include when querying the original schema
14 */
15 headers?: Headers;
16 /**
17 * A custom `fetch` implementation to use when querying the original schema.
18 * Defaults to `cross-fetch`
19 */
20 customFetch?: FetchFn | string;
21 /**
22 * HTTP method to use when querying the original schema.
23 */
24 method?: 'GET' | 'POST';
25 /**
26 * Whether to enable subscriptions on the loaded schema
27 */
28 enableSubscriptions?: boolean;
29 /**
30 * Custom WebSocket implementation used by the loaded schema if subscriptions
31 * are enabled
32 */
33 webSocketImpl?: typeof w3cwebsocket | string;
34 /**
35 * Whether to use the GET HTTP method for queries when querying the original schema
36 */
37 useGETForQueries?: boolean;
38}
39/**
40 * This loader loads a schema from a URL. The loaded schema is a fully-executable,
41 * remote schema since it's created using [@graphql-tools/wrap](/docs/remote-schemas).
42 *
43 * ```
44 * const schema = await loadSchema('http://localhost:3000/graphql', {
45 * loaders: [
46 * new UrlLoader(),
47 * ]
48 * });
49 * ```
50 */
51export declare class UrlLoader implements DocumentLoader<LoadFromUrlOptions> {
52 loaderId(): string;
53 canLoad(pointer: SchemaPointerSingle, options: LoadFromUrlOptions): Promise<boolean>;
54 canLoadSync(pointer: SchemaPointerSingle, _options: LoadFromUrlOptions): boolean;
55 buildAsyncExecutor({ pointer, fetch, extraHeaders, defaultMethod, useGETForQueries, }: {
56 pointer: string;
57 fetch: typeof crossFetch;
58 extraHeaders: any;
59 defaultMethod: 'GET' | 'POST';
60 useGETForQueries: boolean;
61 }): AsyncExecutor;
62 buildSubscriber(pointer: string, webSocketImpl: typeof w3cwebsocket): Subscriber;
63 getExecutorAndSubscriber(pointer: SchemaPointerSingle, options: LoadFromUrlOptions): Promise<{
64 executor: AsyncExecutor;
65 subscriber: Subscriber;
66 }>;
67 getSubschemaConfig(pointer: SchemaPointerSingle, options: LoadFromUrlOptions): Promise<{
68 schema: import("graphql").GraphQLSchema;
69 executor: AsyncExecutor;
70 subscriber: Subscriber;
71 }>;
72 load(pointer: SchemaPointerSingle, options: LoadFromUrlOptions): Promise<Source>;
73 loadSync(): never;
74}
75export {};