|
1 | 1 | import { parse } from 'graphql';
|
2 | 2 | import syncFetch from 'sync-fetch';
|
3 |
| -import { ValueOrPromise } from 'value-or-promise'; |
4 | 3 | import { AsyncFetchFn, FetchFn, SyncFetchFn } from '@graphql-tools/executor-http';
|
5 | 4 | import {
|
6 | 5 | gqlPluckFromCodeStringSync,
|
|
9 | 8 | import {
|
10 | 9 | BaseLoaderOptions,
|
11 | 10 | Loader,
|
| 11 | + mapMaybePromise, |
| 12 | + MaybePromise, |
12 | 13 | parseGraphQLJSON,
|
13 | 14 | parseGraphQLSDL,
|
14 | 15 | Source,
|
@@ -90,30 +91,31 @@ export class GithubLoader implements Loader<GithubLoaderOptions> {
|
90 | 91 | pointer: string,
|
91 | 92 | options: GithubLoaderOptions,
|
92 | 93 | fetchFn: FetchFn,
|
93 |
| - ): Promise<Source[]> | Source[] { |
| 94 | + ): MaybePromise<Source[]> { |
94 | 95 | if (!this.canLoadSync(pointer)) {
|
95 | 96 | return [];
|
96 | 97 | }
|
97 | 98 | const { owner, name, ref, path } = extractData(pointer);
|
98 |
| - return new ValueOrPromise(() => |
99 |
| - fetchFn( |
100 |
| - 'https://api.github.com/graphql', |
101 |
| - this.prepareRequest({ owner, ref, path, name, options }), |
| 99 | + return mapMaybePromise( |
| 100 | + mapMaybePromise( |
| 101 | + fetchFn( |
| 102 | + 'https://api.github.com/graphql', |
| 103 | + this.prepareRequest({ owner, ref, path, name, options }), |
| 104 | + ), |
| 105 | + response => { |
| 106 | + const contentType = response.headers.get('content-type'); |
| 107 | + if (contentType && contentType.includes('application/json')) { |
| 108 | + return response.json(); |
| 109 | + } else { |
| 110 | + return response.text(); |
| 111 | + } |
| 112 | + }, |
102 | 113 | ),
|
103 |
| - ) |
104 |
| - .then(response => { |
105 |
| - const contentType = response.headers.get('content-type'); |
106 |
| - if (contentType && contentType.includes('application/json')) { |
107 |
| - return response.json(); |
108 |
| - } else { |
109 |
| - return response.text(); |
110 |
| - } |
111 |
| - }) |
112 |
| - .then(response => { |
| 114 | + response => { |
113 | 115 | const status = response.status;
|
114 | 116 | return this.handleResponse({ pointer, path, options, response, status });
|
115 |
| - }) |
116 |
| - .resolve(); |
| 117 | + }, |
| 118 | + ); |
117 | 119 | }
|
118 | 120 |
|
119 | 121 | load(pointer: string, options: GithubLoaderOptions): Promise<Source[]> {
|
|
0 commit comments