@stephenchenorg/astro 1.0.0 → 1.1.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/README.md CHANGED
@@ -20,5 +20,5 @@ yarn build
20
20
 
21
21
  ```bash
22
22
  npm login
23
- npm publish
23
+ npm run release
24
24
  ```
@@ -0,0 +1,7 @@
1
+ import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
2
+ export interface CreateGraphQLAPIOptions {
3
+ endpoint: string;
4
+ defaultVariables?: Record<string, any> | (() => Record<string, any>);
5
+ }
6
+ 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) => any;
7
+ export { gql } from 'graphql-tag';
@@ -0,0 +1,30 @@
1
+ import { AwesomeGraphQLClient, GraphQLRequestError as AwesomeGraphQLRequestError } from "awesome-graphql-client";
2
+ import { print } from "graphql/language/printer";
3
+ import { GraphQLRequestError } from "./error.js";
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
+ return new Promise((resolve, reject) => {
12
+ client.request(query, {
13
+ ...defaultVariables,
14
+ ...variables
15
+ }).then((data) => resolve(data)).catch((error) => {
16
+ if (error instanceof AwesomeGraphQLRequestError) {
17
+ reject(new GraphQLRequestError({
18
+ message: error.message,
19
+ query: error.query,
20
+ variables: error.variables,
21
+ extensions: error.extensions
22
+ }));
23
+ } else {
24
+ reject(error);
25
+ }
26
+ });
27
+ });
28
+ };
29
+ }
30
+ export { gql } from "graphql-tag";
@@ -1 +1,2 @@
1
+ export * from './fetch';
1
2
  export * from './error';
package/dist/api/index.js CHANGED
@@ -1 +1,2 @@
1
+ export * from "./fetch.js";
1
2
  export * from "./error.js";
@@ -1 +1 @@
1
- export declare const companySettingFields: import("graphql/language/ast").DocumentNode;
1
+ export declare const companySettingFields: import("graphql").DocumentNode;
@@ -1,3 +1,3 @@
1
- export declare const imageFields: import("graphql/language/ast").DocumentNode;
2
- export declare const coverFields: import("graphql/language/ast").DocumentNode;
3
- export declare const backgroundFields: import("graphql/language/ast").DocumentNode;
1
+ export declare const imageFields: import("graphql").DocumentNode;
2
+ export declare const coverFields: import("graphql").DocumentNode;
3
+ export declare const backgroundFields: import("graphql").DocumentNode;
@@ -2,4 +2,4 @@
2
2
  * Page fields fragment requires explicit import image
3
3
  * fields fragment `imageFields` from Image module.
4
4
  */
5
- export declare const pageFields: import("graphql/language/ast").DocumentNode;
5
+ export declare const pageFields: import("graphql").DocumentNode;
@@ -1 +1 @@
1
- export declare const seoMetaFields: (dummyClass: string) => import("graphql/language/ast").DocumentNode;
1
+ export declare const seoMetaFields: (dummyClass: string) => import("graphql").DocumentNode;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stephenchenorg/astro",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "description": "Stephenchenorg Astro 前端通用套件",
6
6
  "license": "MIT",
7
7
  "homepage": "https://stephenchenorg-astro.netlify.app",
@@ -64,6 +64,7 @@
64
64
  "astro": "^5.0.0"
65
65
  },
66
66
  "dependencies": {
67
+ "@graphql-typed-document-node/core": "^3.2.0",
67
68
  "awesome-graphql-client": "^2.1.0",
68
69
  "graphql": "^16.10.0",
69
70
  "graphql-tag": "^2.12.6",
@@ -72,10 +73,9 @@
72
73
  },
73
74
  "devDependencies": {
74
75
  "@astrojs/check": "^0.9.4",
75
- "@graphql-typed-document-node/core": "^3.2.0",
76
- "astro": "^5.3.1",
76
+ "astro": "^5.4.1",
77
77
  "bumpp": "^10.0.3",
78
78
  "mkdist": "^2.2.0",
79
- "typescript": "~5.7.2"
79
+ "typescript": "~5.7.3"
80
80
  }
81
81
  }