@stephenchenorg/astro 1.4.0 → 1.6.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.
@@ -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
- headers?: Record<string, string> | (() => Record<string, string>);
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
- return function graphQLAPI(query, variables = {}) {
6
- const client = new AwesomeGraphQLClient({
7
- endpoint: options.endpoint,
8
- formatQuery: (query2) => print(query2)
9
- });
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
- };
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
- }, fetchOptions).then((data) => resolve(data)).catch((error) => {
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.0",
4
+ "version": "1.6.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"
@@ -69,17 +69,17 @@
69
69
  "awesome-graphql-client": "^2.1.0",
70
70
  "graphql": "^16.10.0",
71
71
  "graphql-tag": "^2.12.6",
72
- "nanostores": "^0.11.4",
73
- "query-string": "^9.1.1"
72
+ "nanostores": "^1.0.1",
73
+ "query-string": "^9.1.2"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@astrojs/check": "^0.9.4",
77
77
  "@ycs77/eslint-config": "^4.1.0",
78
- "astro": "^5.4.1",
79
- "bumpp": "^10.0.3",
80
- "eslint": "^9.21.0",
78
+ "astro": "^5.7.10",
79
+ "bumpp": "^10.1.0",
80
+ "eslint": "^9.26.0",
81
81
  "eslint-plugin-astro": "^1.3.1",
82
- "mkdist": "^2.2.0",
83
- "typescript": "~5.7.3"
82
+ "mkdist": "^2.3.0",
83
+ "typescript": "~5.8.3"
84
84
  }
85
85
  }