UNPKG

1.67 kBTypeScriptView Raw
1import { Loader, BaseLoaderOptions, Source } from '@graphql-tools/utils';
2import { GraphQLTagPluckOptions } from '@graphql-tools/graphql-tag-pluck';
3import syncFetch from '@ardatan/sync-fetch';
4import { fetch as asyncFetch } from '@whatwg-node/fetch';
5/**
6 * Additional options for loading from GitHub
7 */
8export interface GithubLoaderOptions extends BaseLoaderOptions {
9 /**
10 * A GitHub access token
11 */
12 token: string;
13 /**
14 * Additional options to pass to `graphql-tag-pluck`
15 */
16 pluckConfig?: GraphQLTagPluckOptions;
17 customFetch?: typeof asyncFetch | typeof syncFetch;
18}
19/**
20 * This loader loads a file from GitHub.
21 *
22 * ```js
23 * const typeDefs = await loadTypedefs('github:githubUser/githubRepo#branchName:path/to/file.ts', {
24 * loaders: [new GithubLoader()],
25 * token: YOUR_GITHUB_TOKEN,
26 * })
27 * ```
28 */
29export declare class GithubLoader implements Loader<GithubLoaderOptions> {
30 canLoad(pointer: string): Promise<boolean>;
31 canLoadSync(pointer: string): boolean;
32 load(pointer: string, options: GithubLoaderOptions): Promise<Source[]>;
33 loadSync(pointer: string, options: GithubLoaderOptions): Source[];
34 handleResponse({ pointer, path, options, response, status, }: {
35 pointer: string;
36 path: string;
37 options: any;
38 response: any;
39 status: number;
40 }): Source[] | {
41 location: string | undefined;
42 document: import("graphql").DocumentNode;
43 }[];
44 prepareRequest({ owner, ref, path, name, options, }: {
45 owner: string;
46 ref: string;
47 path: string;
48 name: string;
49 options: GithubLoaderOptions;
50 }): RequestInit;
51}