@stephenchenorg/astro 1.2.3 → 1.3.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/error.d.ts +2 -0
- package/dist/api/fetch.d.ts +1 -0
- package/dist/api/fetch.js +4 -1
- package/package.json +1 -1
package/dist/api/error.d.ts
CHANGED
package/dist/api/fetch.d.ts
CHANGED
|
@@ -2,6 +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
|
+
headers?: Record<string, string> | (() => Record<string, string>);
|
|
5
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
8
|
export { gql } from 'graphql-tag';
|
package/dist/api/fetch.js
CHANGED
|
@@ -8,11 +8,14 @@ export function createGraphQLAPI(options) {
|
|
|
8
8
|
formatQuery: (query2) => print(query2)
|
|
9
9
|
});
|
|
10
10
|
const defaultVariables = typeof options.defaultVariables === "function" ? options.defaultVariables() : options.defaultVariables ?? {};
|
|
11
|
+
const fetchOptions = {
|
|
12
|
+
headers: typeof options.headers === "function" ? options.headers() : options.headers
|
|
13
|
+
};
|
|
11
14
|
return new Promise((resolve, reject) => {
|
|
12
15
|
client.request(query, {
|
|
13
16
|
...defaultVariables,
|
|
14
17
|
...variables
|
|
15
|
-
}).then((data) => resolve(data)).catch((error) => {
|
|
18
|
+
}, fetchOptions).then((data) => resolve(data)).catch((error) => {
|
|
16
19
|
if (error instanceof AwesomeGraphQLRequestError) {
|
|
17
20
|
reject(new GraphQLRequestError({
|
|
18
21
|
message: error.message,
|