@graphql-tools/github-loader 7.3.6-alpha-d9e3cbee.0 → 7.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.js +9 -4
- package/esm/index.js +9 -4
- package/package.json +2 -2
- package/typings/index.d.ts +3 -2
package/cjs/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const utils_1 = require("@graphql-tools/utils");
|
|
6
6
|
const graphql_tag_pluck_1 = require("@graphql-tools/graphql-tag-pluck");
|
|
7
7
|
const graphql_1 = require("graphql");
|
|
8
|
-
const sync_fetch_1 = tslib_1.__importDefault(require("sync-fetch"));
|
|
8
|
+
const sync_fetch_1 = tslib_1.__importDefault(require("@ardatan/sync-fetch"));
|
|
9
9
|
const fetch_1 = require("@whatwg-node/fetch");
|
|
10
10
|
// github:owner/name#ref:path/to/file
|
|
11
11
|
function extractData(pointer) {
|
|
@@ -44,7 +44,8 @@ class GithubLoader {
|
|
|
44
44
|
const fetch = options.customFetch || fetch_1.fetch;
|
|
45
45
|
const request = await fetch('https://api.github.com/graphql', this.prepareRequest({ owner, ref, path, name, options }));
|
|
46
46
|
const response = await request.json();
|
|
47
|
-
|
|
47
|
+
const status = request.status;
|
|
48
|
+
return this.handleResponse({ pointer, path, options, response, status });
|
|
48
49
|
}
|
|
49
50
|
loadSync(pointer, options) {
|
|
50
51
|
if (!this.canLoadSync(pointer)) {
|
|
@@ -54,13 +55,17 @@ class GithubLoader {
|
|
|
54
55
|
const fetch = options.customFetch || sync_fetch_1.default;
|
|
55
56
|
const request = fetch('https://api.github.com/graphql', this.prepareRequest({ owner, ref, path, name, options }));
|
|
56
57
|
const response = request.json();
|
|
57
|
-
|
|
58
|
+
const status = request.status;
|
|
59
|
+
return this.handleResponse({ pointer, path, options, response, status });
|
|
58
60
|
}
|
|
59
|
-
handleResponse({ pointer, path, options, response }) {
|
|
61
|
+
handleResponse({ pointer, path, options, response, status, }) {
|
|
60
62
|
let errorMessage = null;
|
|
61
63
|
if (response.errors && response.errors.length > 0) {
|
|
62
64
|
errorMessage = response.errors.map((item) => item.message).join(', ');
|
|
63
65
|
}
|
|
66
|
+
else if (status === 401) {
|
|
67
|
+
errorMessage = response.message;
|
|
68
|
+
}
|
|
64
69
|
else if (!response.data) {
|
|
65
70
|
errorMessage = response;
|
|
66
71
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseGraphQLSDL, parseGraphQLJSON } from '@graphql-tools/utils';
|
|
2
2
|
import { gqlPluckFromCodeStringSync } from '@graphql-tools/graphql-tag-pluck';
|
|
3
3
|
import { parse } from 'graphql';
|
|
4
|
-
import syncFetch from 'sync-fetch';
|
|
4
|
+
import syncFetch from '@ardatan/sync-fetch';
|
|
5
5
|
import { fetch as asyncFetch } from '@whatwg-node/fetch';
|
|
6
6
|
// github:owner/name#ref:path/to/file
|
|
7
7
|
function extractData(pointer) {
|
|
@@ -40,7 +40,8 @@ export class GithubLoader {
|
|
|
40
40
|
const fetch = options.customFetch || asyncFetch;
|
|
41
41
|
const request = await fetch('https://api.github.com/graphql', this.prepareRequest({ owner, ref, path, name, options }));
|
|
42
42
|
const response = await request.json();
|
|
43
|
-
|
|
43
|
+
const status = request.status;
|
|
44
|
+
return this.handleResponse({ pointer, path, options, response, status });
|
|
44
45
|
}
|
|
45
46
|
loadSync(pointer, options) {
|
|
46
47
|
if (!this.canLoadSync(pointer)) {
|
|
@@ -50,13 +51,17 @@ export class GithubLoader {
|
|
|
50
51
|
const fetch = options.customFetch || syncFetch;
|
|
51
52
|
const request = fetch('https://api.github.com/graphql', this.prepareRequest({ owner, ref, path, name, options }));
|
|
52
53
|
const response = request.json();
|
|
53
|
-
|
|
54
|
+
const status = request.status;
|
|
55
|
+
return this.handleResponse({ pointer, path, options, response, status });
|
|
54
56
|
}
|
|
55
|
-
handleResponse({ pointer, path, options, response }) {
|
|
57
|
+
handleResponse({ pointer, path, options, response, status, }) {
|
|
56
58
|
let errorMessage = null;
|
|
57
59
|
if (response.errors && response.errors.length > 0) {
|
|
58
60
|
errorMessage = response.errors.map((item) => item.message).join(', ');
|
|
59
61
|
}
|
|
62
|
+
else if (status === 401) {
|
|
63
|
+
errorMessage = response.message;
|
|
64
|
+
}
|
|
60
65
|
else if (!response.data) {
|
|
61
66
|
errorMessage = response;
|
|
62
67
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/github-loader",
|
|
3
|
-
"version": "7.3.6
|
|
3
|
+
"version": "7.3.6",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
+
"@ardatan/sync-fetch": "0.0.1",
|
|
10
11
|
"@graphql-tools/utils": "8.9.0",
|
|
11
12
|
"@graphql-tools/graphql-tag-pluck": "7.3.1",
|
|
12
13
|
"@whatwg-node/fetch": "^0.2.4",
|
|
13
|
-
"sync-fetch": "0.4.1",
|
|
14
14
|
"tslib": "^2.4.0"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
package/typings/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Loader, BaseLoaderOptions, Source } from '@graphql-tools/utils';
|
|
2
2
|
import { GraphQLTagPluckOptions } from '@graphql-tools/graphql-tag-pluck';
|
|
3
|
-
import syncFetch from 'sync-fetch';
|
|
3
|
+
import syncFetch from '@ardatan/sync-fetch';
|
|
4
4
|
import { fetch as asyncFetch } from '@whatwg-node/fetch';
|
|
5
5
|
/**
|
|
6
6
|
* Additional options for loading from GitHub
|
|
@@ -31,11 +31,12 @@ export declare class GithubLoader implements Loader<GithubLoaderOptions> {
|
|
|
31
31
|
canLoadSync(pointer: string): boolean;
|
|
32
32
|
load(pointer: string, options: GithubLoaderOptions): Promise<Source[]>;
|
|
33
33
|
loadSync(pointer: string, options: GithubLoaderOptions): Source[];
|
|
34
|
-
handleResponse({ pointer, path, options, response }: {
|
|
34
|
+
handleResponse({ pointer, path, options, response, status, }: {
|
|
35
35
|
pointer: string;
|
|
36
36
|
path: string;
|
|
37
37
|
options: any;
|
|
38
38
|
response: any;
|
|
39
|
+
status: number;
|
|
39
40
|
}): Source[] | {
|
|
40
41
|
location: string | undefined;
|
|
41
42
|
document: import("graphql").DocumentNode;
|