Skip to content

Commit 2cf8504

Browse files
committed
enhance(github-loader): remove value-or-promise
1 parent d1c8fee commit 2cf8504

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

packages/loaders/github/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@
5656
"@graphql-tools/utils": "^10.7.2",
5757
"@whatwg-node/fetch": "^0.10.0",
5858
"sync-fetch": "0.6.0-2",
59-
"tslib": "^2.4.0",
60-
"value-or-promise": "^1.0.12"
59+
"tslib": "^2.4.0"
6160
},
6261
"publishConfig": {
6362
"directory": "dist",

packages/loaders/github/src/index.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { parse } from 'graphql';
22
import syncFetch from 'sync-fetch';
3-
import { ValueOrPromise } from 'value-or-promise';
43
import { AsyncFetchFn, FetchFn, SyncFetchFn } from '@graphql-tools/executor-http';
54
import {
65
gqlPluckFromCodeStringSync,
@@ -9,6 +8,8 @@ import {
98
import {
109
BaseLoaderOptions,
1110
Loader,
11+
mapMaybePromise,
12+
MaybePromise,
1213
parseGraphQLJSON,
1314
parseGraphQLSDL,
1415
Source,
@@ -90,30 +91,31 @@ export class GithubLoader implements Loader<GithubLoaderOptions> {
9091
pointer: string,
9192
options: GithubLoaderOptions,
9293
fetchFn: FetchFn,
93-
): Promise<Source[]> | Source[] {
94+
): MaybePromise<Source[]> {
9495
if (!this.canLoadSync(pointer)) {
9596
return [];
9697
}
9798
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+
},
102113
),
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 => {
113115
const status = response.status;
114116
return this.handleResponse({ pointer, path, options, response, status });
115-
})
116-
.resolve();
117+
},
118+
);
117119
}
118120

119121
load(pointer: string, options: GithubLoaderOptions): Promise<Source[]> {

0 commit comments

Comments
 (0)