@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.
@@ -7,6 +7,8 @@ interface GraphQLRequestExtensions {
7
7
  line: number;
8
8
  call: number;
9
9
  }[];
10
+ validation?: Record<string, string[]>;
11
+ category?: string;
10
12
  }
11
13
  export declare class GraphQLRequestError extends Error {
12
14
  type: string;
@@ -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,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stephenchenorg/astro",
3
3
  "type": "module",
4
- "version": "1.2.3",
4
+ "version": "1.3.0",
5
5
  "description": "Stephenchenorg Astro 前端通用套件",
6
6
  "license": "MIT",
7
7
  "homepage": "https://stephenchenorg-astro.netlify.app",