@stephenchenorg/astro 1.4.0 → 1.5.0
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/dist/api/fetch.d.ts +2 -2
- package/dist/api/fetch.js +15 -10
- package/package.json +2 -2
package/dist/api/fetch.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
|
2
2
|
export interface CreateGraphQLAPIOptions {
|
|
3
3
|
endpoint: string;
|
|
4
4
|
defaultVariables?: Record<string, any> | (() => Record<string, any>);
|
|
5
|
-
|
|
5
|
+
fetchOptions?: RequestInit | (() => RequestInit);
|
|
6
6
|
}
|
|
7
|
-
export declare function createGraphQLAPI(options: CreateGraphQLAPIOptions): <TData extends Record<string, any>, TVariables extends Record<string, any> = Record<string, any>>(query: TypedDocumentNode<TData, TVariables>, variables?: TVariables) => Promise<TData>;
|
|
7
|
+
export declare function createGraphQLAPI(options: CreateGraphQLAPIOptions): <TData extends Record<string, any>, TVariables extends Record<string, any> = Record<string, any>>(query: TypedDocumentNode<TData, TVariables>, variables?: TVariables, fetchOptions?: RequestInit) => Promise<TData>;
|
|
8
8
|
export { gql } from 'graphql-tag';
|
package/dist/api/fetch.js
CHANGED
|
@@ -2,20 +2,25 @@ import { AwesomeGraphQLClient, GraphQLRequestError as AwesomeGraphQLRequestError
|
|
|
2
2
|
import { print } from "graphql/language/printer";
|
|
3
3
|
import { GraphQLNotFoundError, GraphQLRequestError, GraphQLValidationError } from "./error.js";
|
|
4
4
|
export function createGraphQLAPI(options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const defaultVariables = typeof options.defaultVariables === "function" ? options.defaultVariables() : options.defaultVariables
|
|
11
|
-
const
|
|
12
|
-
headers: typeof options.headers === "function" ? options.headers() : options.headers
|
|
13
|
-
};
|
|
5
|
+
const client = new AwesomeGraphQLClient({
|
|
6
|
+
endpoint: options.endpoint,
|
|
7
|
+
formatQuery: (query) => print(query)
|
|
8
|
+
});
|
|
9
|
+
return function graphQLAPI(query, variables, fetchOptions) {
|
|
10
|
+
const defaultVariables = typeof options.defaultVariables === "function" ? options.defaultVariables() : options.defaultVariables;
|
|
11
|
+
const defaultFetchOptions = typeof options.fetchOptions === "function" ? options.fetchOptions() : options.fetchOptions;
|
|
14
12
|
return new Promise((resolve, reject) => {
|
|
15
13
|
client.request(query, {
|
|
16
14
|
...defaultVariables,
|
|
17
15
|
...variables
|
|
18
|
-
},
|
|
16
|
+
}, {
|
|
17
|
+
...defaultFetchOptions,
|
|
18
|
+
...fetchOptions,
|
|
19
|
+
headers: {
|
|
20
|
+
...defaultFetchOptions?.headers,
|
|
21
|
+
...fetchOptions?.headers
|
|
22
|
+
}
|
|
23
|
+
}).then((data) => resolve(data)).catch((error) => {
|
|
19
24
|
if (error instanceof AwesomeGraphQLRequestError) {
|
|
20
25
|
const fieldError = error.fieldErrors?.[0];
|
|
21
26
|
const code = fieldError?.code;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stephenchenorg/astro",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.0",
|
|
5
5
|
"description": "Stephenchenorg Astro 前端通用套件",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://stephenchenorg-astro.netlify.app",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "mkdist --declaration --ext=js",
|
|
59
|
-
"lint": "eslint
|
|
59
|
+
"lint": "eslint \"*.{js,ts,json}\" \"src/**/*.ts\"",
|
|
60
60
|
"code-check": "astro check && npm run lint",
|
|
61
61
|
"prepack": "npm run build",
|
|
62
62
|
"release": "bumpp --commit \"Release v%s\" && npm publish"
|