@constructive-io/graphql-codegen 4.31.1 → 4.32.1

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.
@@ -13,6 +13,7 @@ import type {
13
13
  GraphQLError,
14
14
  QueryResult,
15
15
  } from '@constructive-io/graphql-query/runtime';
16
+ import { createFetch } from '@constructive-io/graphql-query/runtime';
16
17
 
17
18
  export type {
18
19
  GraphQLAdapter,
@@ -22,23 +23,30 @@ export type {
22
23
 
23
24
  /**
24
25
  * Default adapter that uses fetch for HTTP requests.
25
- * This is used when no custom adapter is provided.
26
+ *
27
+ * When no custom fetch is provided, uses @constructive-io/fetch which
28
+ * handles *.localhost DNS rewriting and Host header preservation in
29
+ * Node.js. Pass a custom fetch to override for test mocking or custom
30
+ * proxy/credentials.
26
31
  */
27
32
  export class FetchAdapter implements GraphQLAdapter {
28
33
  private headers: Record<string, string>;
34
+ private fetchFn: typeof globalThis.fetch;
29
35
 
30
36
  constructor(
31
37
  private endpoint: string,
32
38
  headers?: Record<string, string>,
39
+ fetchFn?: typeof globalThis.fetch,
33
40
  ) {
34
41
  this.headers = headers ?? {};
42
+ this.fetchFn = fetchFn ?? createFetch();
35
43
  }
36
44
 
37
45
  async execute<T>(
38
46
  document: string,
39
47
  variables?: Record<string, unknown>,
40
48
  ): Promise<QueryResult<T>> {
41
- const response = await fetch(this.endpoint, {
49
+ const response = await this.fetchFn(this.endpoint, {
42
50
  method: 'POST',
43
51
  headers: {
44
52
  'Content-Type': 'application/json',
@@ -92,7 +100,7 @@ export class FetchAdapter implements GraphQLAdapter {
92
100
 
93
101
  /**
94
102
  * Configuration for creating an ORM client.
95
- * Either provide endpoint (and optional headers) for HTTP requests,
103
+ * Either provide endpoint (and optional headers/fetch) for HTTP requests,
96
104
  * or provide a custom adapter for alternative execution strategies.
97
105
  */
98
106
  export interface OrmClientConfig {
@@ -100,7 +108,14 @@ export interface OrmClientConfig {
100
108
  endpoint?: string;
101
109
  /** Default headers for HTTP requests (only used with endpoint) */
102
110
  headers?: Record<string, string>;
103
- /** Custom adapter for GraphQL execution (overrides endpoint/headers) */
111
+ /**
112
+ * Custom fetch implementation. Defaults to createFetch() from
113
+ * @constructive-io/graphql-query/runtime which handles *.localhost
114
+ * DNS and Host headers in Node.js. Pass your own for test mocking
115
+ * or custom proxy/credentials.
116
+ */
117
+ fetch?: typeof globalThis.fetch;
118
+ /** Custom adapter for GraphQL execution (overrides endpoint/headers/fetch) */
104
119
  adapter?: GraphQLAdapter;
105
120
  }
106
121
 
@@ -125,7 +140,11 @@ export class OrmClient {
125
140
  if (config.adapter) {
126
141
  this.adapter = config.adapter;
127
142
  } else if (config.endpoint) {
128
- this.adapter = new FetchAdapter(config.endpoint, config.headers);
143
+ this.adapter = new FetchAdapter(
144
+ config.endpoint,
145
+ config.headers,
146
+ config.fetch,
147
+ );
129
148
  } else {
130
149
  throw new Error(
131
150
  'OrmClientConfig requires either an endpoint or a custom adapter',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/graphql-codegen",
3
- "version": "4.31.1",
3
+ "version": "4.32.1",
4
4
  "description": "GraphQL SDK generator for Constructive databases with React Query hooks",
5
5
  "keywords": [
6
6
  "graphql",
@@ -56,7 +56,7 @@
56
56
  "@0no-co/graphql.web": "^1.1.2",
57
57
  "@babel/generator": "^7.29.1",
58
58
  "@babel/types": "^7.29.0",
59
- "@constructive-io/graphql-query": "^3.15.1",
59
+ "@constructive-io/graphql-query": "^3.15.3",
60
60
  "@constructive-io/graphql-types": "^3.5.1",
61
61
  "@inquirerer/utils": "^3.3.5",
62
62
  "@pgpmjs/core": "^6.12.4",
@@ -64,7 +64,7 @@
64
64
  "deepmerge": "^4.3.1",
65
65
  "find-and-require-package-json": "^0.9.1",
66
66
  "gql-ast": "^3.5.0",
67
- "graphile-schema": "^1.13.10",
67
+ "graphile-schema": "^1.13.12",
68
68
  "graphql": "16.13.0",
69
69
  "inflekt": "^0.7.1",
70
70
  "inquirerer": "^4.7.0",
@@ -100,5 +100,5 @@
100
100
  "tsx": "^4.21.0",
101
101
  "typescript": "^5.9.3"
102
102
  },
103
- "gitHead": "90b15540015a927e45846923843fc1af36f5bed7"
103
+ "gitHead": "058b8200e99eb505477d1599ee0d5ab795aa0123"
104
104
  }