|
1 | | -import fetch from 'node-fetch'; |
2 | | -import { |
3 | | - getIntrospectionQuery, |
4 | | -} from 'graphql'; |
| 1 | +import { getIntrospectionQuery } from "graphql"; |
5 | 2 |
|
6 | | -export async function getGqlSchema ({ moduleName, cache, url, token }) { |
| 3 | +export async function getGqlSchema({ moduleName, cache, url, token }) { |
7 | 4 | try { |
8 | | - const introspectionQuery = getIntrospectionQuery() |
| 5 | + const introspectionQuery = getIntrospectionQuery(); |
9 | 6 |
|
10 | | - const response = await fetch( |
11 | | - url, |
12 | | - { |
13 | | - method: 'POST', |
14 | | - headers: |
15 | | - token |
16 | | - ? { |
17 | | - 'Content-Type': 'application/json', |
18 | | - Authorization: `Bearer ${token}` |
19 | | - } |
20 | | - : { |
21 | | - 'Content-Type': 'application/json' |
22 | | - }, |
23 | | - body: JSON.stringify({ query: introspectionQuery }) |
24 | | - } |
25 | | - ) |
| 7 | + const response = await fetch(url, { |
| 8 | + method: "POST", |
| 9 | + headers: token |
| 10 | + ? { |
| 11 | + "Content-Type": "application/json", |
| 12 | + Authorization: `Bearer ${token}`, |
| 13 | + } |
| 14 | + : { |
| 15 | + "Content-Type": "application/json", |
| 16 | + }, |
| 17 | + body: JSON.stringify({ query: introspectionQuery }), |
| 18 | + }); |
26 | 19 |
|
27 | | - const { data: schema, errors } = await response.json() |
| 20 | + const { data: schema, errors } = await response.json(); |
28 | 21 |
|
29 | 22 | if (errors) { |
30 | | - throw new Error(errors |
31 | | - .map(err => "- " + err.message) |
32 | | - .join('\n') |
33 | | - ) |
| 23 | + throw new Error(errors.map((err) => "- " + err.message).join("\n")); |
34 | 24 | } |
35 | 25 |
|
36 | | - return { moduleName, cache, schema } |
| 26 | + return { moduleName, cache, schema }; |
37 | 27 | } catch (err) { |
38 | | - console.error('failed to get gql schema', err) |
39 | | - throw (err) |
| 28 | + console.error("failed to get gql schema", err); |
| 29 | + throw err; |
40 | 30 | } |
41 | 31 | } |
0 commit comments