@ctil/gql 1.0.6 → 1.0.7

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/index.d.cts CHANGED
@@ -5,6 +5,10 @@ interface RequestConfig {
5
5
  Authorization?: string;
6
6
  headers?: Record<string, string>;
7
7
  loginInfo?: UserToken | null | undefined;
8
+ /** 浏览器下是否携带跨域 Cookie */
9
+ withCredentials?: boolean;
10
+ /** 浏览器下的请求模式,默认 'cors' */
11
+ corsMode?: RequestMode;
8
12
  }
9
13
  /** 拦截器接口 */
10
14
  interface RequestInterceptor {
package/dist/index.d.ts CHANGED
@@ -5,6 +5,10 @@ interface RequestConfig {
5
5
  Authorization?: string;
6
6
  headers?: Record<string, string>;
7
7
  loginInfo?: UserToken | null | undefined;
8
+ /** 浏览器下是否携带跨域 Cookie */
9
+ withCredentials?: boolean;
10
+ /** 浏览器下的请求模式,默认 'cors' */
11
+ corsMode?: RequestMode;
8
12
  }
9
13
  /** 拦截器接口 */
10
14
  interface RequestInterceptor {
package/dist/index.js CHANGED
@@ -1552,9 +1552,19 @@ var CCRequest = class {
1552
1552
  }
1553
1553
  /** 构建 GraphQLClient 实例 */
1554
1554
  buildClient() {
1555
- this.client = new GraphQLClient(this.config.endpoint || "/graphql", {
1556
- headers: this.headers
1557
- });
1555
+ const options = { headers: this.headers };
1556
+ if (isBrowser) {
1557
+ const corsMode = this.config.corsMode || "cors";
1558
+ const withCred = !!this.config.withCredentials;
1559
+ options.fetch = (input, init) => {
1560
+ return fetch(input, {
1561
+ ...init,
1562
+ mode: corsMode,
1563
+ credentials: withCred ? "include" : init?.credentials
1564
+ });
1565
+ };
1566
+ }
1567
+ this.client = new GraphQLClient(this.config.endpoint || "/graphql", options);
1558
1568
  }
1559
1569
  /** 构建初始 headers */
1560
1570
  buildHeaders(config) {