@stephenchenorg/astro 1.0.1 → 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/dist/api/fetch.d.ts +7 -0
- package/dist/api/fetch.js +30 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/company-setting/fragments.d.ts +1 -1
- package/dist/image/fragments.d.ts +3 -3
- package/dist/page/field/fragments.d.ts +1 -1
- package/dist/page/seo-meta/fragments.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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";
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const companySettingFields: import("graphql
|
|
1
|
+
export declare const companySettingFields: import("graphql").DocumentNode;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const imageFields: import("graphql
|
|
2
|
-
export declare const coverFields: import("graphql
|
|
3
|
-
export declare const backgroundFields: import("graphql
|
|
1
|
+
export declare const imageFields: import("graphql").DocumentNode;
|
|
2
|
+
export declare const coverFields: import("graphql").DocumentNode;
|
|
3
|
+
export declare const backgroundFields: import("graphql").DocumentNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const seoMetaFields: (dummyClass: string) => import("graphql
|
|
1
|
+
export declare const seoMetaFields: (dummyClass: string) => import("graphql").DocumentNode;
|