@schema-hub/zod-graphql-client 0.0.13 → 0.0.15
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/package.json +25 -7
- package/readme.md +127 -45
- package/sbom.cdx.json +101 -0
- package/zod-graphql-client/client.d.ts +10 -24
- package/zod-graphql-client/client.d.ts.map +1 -1
- package/zod-graphql-client/client.js +111 -93
- package/zod-graphql-client/client.js.map +1 -1
- package/zod-graphql-client/define-variables.d.ts +28 -0
- package/zod-graphql-client/define-variables.d.ts.map +1 -0
- package/zod-graphql-client/define-variables.js +11 -0
- package/zod-graphql-client/define-variables.js.map +1 -0
- package/zod-graphql-client/entry-point.d.ts +12 -4
- package/zod-graphql-client/entry-point.d.ts.map +1 -1
- package/zod-graphql-client/entry-point.js +4 -1
- package/zod-graphql-client/entry-point.js.map +1 -1
- package/zod-graphql-client/graphql-error.d.ts +12 -0
- package/zod-graphql-client/graphql-error.d.ts.map +1 -0
- package/zod-graphql-client/graphql-error.js +2 -36
- package/zod-graphql-client/graphql-error.js.map +1 -1
- package/zod-graphql-client/graphql-response.js +3 -3
- package/zod-graphql-client/graphql-response.js.map +1 -1
- package/zod-graphql-client/infer-graphql-type.d.ts +2 -0
- package/zod-graphql-client/infer-graphql-type.d.ts.map +1 -0
- package/zod-graphql-client/infer-graphql-type.js +67 -0
- package/zod-graphql-client/infer-graphql-type.js.map +1 -0
- package/zod-graphql-client/operation-error.d.ts +7 -7
- package/zod-graphql-client/operation-error.d.ts.map +1 -1
- package/zod-graphql-client/operation-error.js +2 -1
- package/zod-graphql-client/operation-error.js.map +1 -1
- package/zod-graphql-client/operation-handle.d.ts +13 -0
- package/zod-graphql-client/operation-handle.d.ts.map +1 -0
- package/zod-graphql-client/operation-handle.js +1 -0
- package/zod-graphql-client/operation-handle.js.map +1 -0
- package/zod-graphql-client/operation-payload.d.ts +24 -0
- package/zod-graphql-client/operation-payload.d.ts.map +1 -0
- package/zod-graphql-client/operation-payload.js +70 -0
- package/zod-graphql-client/operation-payload.js.map +1 -0
- package/zod-graphql-client/operation-result.d.ts +1 -1
- package/zod-graphql-client/persisted-query.d.ts +9 -0
- package/zod-graphql-client/persisted-query.d.ts.map +1 -0
- package/zod-graphql-client/persisted-query.js +50 -0
- package/zod-graphql-client/persisted-query.js.map +1 -0
- package/zod-graphql-client/variable-entry.d.ts +11 -0
- package/zod-graphql-client/variable-entry.d.ts.map +1 -0
- package/zod-graphql-client/variable-entry.js +2 -0
- package/zod-graphql-client/variable-entry.js.map +1 -0
- package/zod-graphql-client/variables.d.ts +0 -9
- package/zod-graphql-client/variables.d.ts.map +0 -1
- package/zod-graphql-client/variables.js +0 -15
- package/zod-graphql-client/variables.js.map +0 -1
|
@@ -1,18 +1,70 @@
|
|
|
1
1
|
import { TimeoutError } from 'ky';
|
|
2
|
-
import { safeParse } from '@schema-hub/zod-error-formatter
|
|
3
|
-
import { buildGraphqlMutation, buildGraphqlQuery } from '@schema-hub/zod-graphql-query-builder/zod-graphql-query-builder/entry-point.js';
|
|
2
|
+
import { safeParse } from '@schema-hub/zod-error-formatter';
|
|
4
3
|
import { parseGraphqlResponse } from './graphql-response.js';
|
|
5
4
|
import { GraphqlOperationError } from './operation-error.js';
|
|
6
|
-
import {
|
|
5
|
+
import { buildOperationPayload, resolveOperationInputs, toPersistedQueryPayload } from './operation-payload.js';
|
|
6
|
+
import { detectPersistedQueryRetryReason } from './persisted-query.js';
|
|
7
7
|
const defaultRequestTimeout = 10_000;
|
|
8
8
|
const successResponseStatusCode = 200;
|
|
9
|
+
export function extractDataOrThrow(result) {
|
|
10
|
+
if (result.success) {
|
|
11
|
+
return result.data;
|
|
12
|
+
}
|
|
13
|
+
throw new GraphqlOperationError(result.errorDetails);
|
|
14
|
+
}
|
|
15
|
+
async function parseServerResponse(response) {
|
|
16
|
+
try {
|
|
17
|
+
const responseBody = await response.json();
|
|
18
|
+
return {
|
|
19
|
+
success: true,
|
|
20
|
+
data: responseBody
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
const causedByMessage = error instanceof Error ? `: ${error.message}` : '';
|
|
25
|
+
return {
|
|
26
|
+
success: false,
|
|
27
|
+
errorDetails: {
|
|
28
|
+
type: 'server',
|
|
29
|
+
statusCode: response.status,
|
|
30
|
+
message: `Failed to parse response body${causedByMessage}`,
|
|
31
|
+
cause: error
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function parseResponseData(schema, data) {
|
|
37
|
+
const dataParseResult = safeParse(schema, data);
|
|
38
|
+
if (dataParseResult.success) {
|
|
39
|
+
return {
|
|
40
|
+
success: true,
|
|
41
|
+
data: dataParseResult.data
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
success: false,
|
|
46
|
+
errorDetails: {
|
|
47
|
+
type: 'validation',
|
|
48
|
+
message: 'GraphQL response data doesn’t match the expected schema',
|
|
49
|
+
issues: dataParseResult.error.issues
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function parseAndValidate(schema, rawResponse) {
|
|
54
|
+
const graphqlResponseParseResult = parseGraphqlResponse(rawResponse);
|
|
55
|
+
if (graphqlResponseParseResult.success) {
|
|
56
|
+
return parseResponseData(schema, graphqlResponseParseResult.data);
|
|
57
|
+
}
|
|
58
|
+
return graphqlResponseParseResult;
|
|
59
|
+
}
|
|
9
60
|
function mapUnknownNetworkErrorToFailureResult(error, timeout) {
|
|
10
61
|
if (error instanceof TimeoutError) {
|
|
11
62
|
return {
|
|
12
63
|
success: false,
|
|
13
64
|
errorDetails: {
|
|
14
65
|
type: 'network',
|
|
15
|
-
message: `Request timed out after ${timeout}ms
|
|
66
|
+
message: `Request timed out after ${timeout}ms`,
|
|
67
|
+
cause: error
|
|
16
68
|
}
|
|
17
69
|
};
|
|
18
70
|
}
|
|
@@ -21,7 +73,8 @@ function mapUnknownNetworkErrorToFailureResult(error, timeout) {
|
|
|
21
73
|
success: false,
|
|
22
74
|
errorDetails: {
|
|
23
75
|
type: 'network',
|
|
24
|
-
message: error.message
|
|
76
|
+
message: error.message,
|
|
77
|
+
cause: error
|
|
25
78
|
}
|
|
26
79
|
};
|
|
27
80
|
}
|
|
@@ -29,10 +82,20 @@ function mapUnknownNetworkErrorToFailureResult(error, timeout) {
|
|
|
29
82
|
success: false,
|
|
30
83
|
errorDetails: {
|
|
31
84
|
type: 'unknown',
|
|
32
|
-
message: 'Unknown error occurred'
|
|
85
|
+
message: 'Unknown error occurred',
|
|
86
|
+
cause: error
|
|
33
87
|
}
|
|
34
88
|
};
|
|
35
89
|
}
|
|
90
|
+
function toBuildPayloadInput(operationType, inputs) {
|
|
91
|
+
return {
|
|
92
|
+
schema: inputs.schema,
|
|
93
|
+
operationType,
|
|
94
|
+
operationName: inputs.operationName,
|
|
95
|
+
variableDefinitions: inputs.variableDefinitions,
|
|
96
|
+
variableValues: inputs.variableValues
|
|
97
|
+
};
|
|
98
|
+
}
|
|
36
99
|
export function createClientFactory(dependencies) {
|
|
37
100
|
const { ky } = dependencies;
|
|
38
101
|
return function createClient(clientOptions) {
|
|
@@ -48,62 +111,6 @@ export function createClientFactory(dependencies) {
|
|
|
48
111
|
retry: 0
|
|
49
112
|
};
|
|
50
113
|
}
|
|
51
|
-
function prepareRequestPayload(schema, operationType, options) {
|
|
52
|
-
const { variables = {} } = options;
|
|
53
|
-
const variableDefinitions = extractVariableDefinitions(variables);
|
|
54
|
-
const variableValues = extractVariableValues(variables);
|
|
55
|
-
const serializedQuery = operationType === 'query' ?
|
|
56
|
-
buildGraphqlQuery(schema, {
|
|
57
|
-
operationName: options.operationName,
|
|
58
|
-
variableDefinitions
|
|
59
|
-
}) :
|
|
60
|
-
buildGraphqlMutation(schema, {
|
|
61
|
-
operationName: options.operationName,
|
|
62
|
-
variableDefinitions
|
|
63
|
-
});
|
|
64
|
-
return {
|
|
65
|
-
query: serializedQuery,
|
|
66
|
-
variables: variableValues,
|
|
67
|
-
operationName: options.operationName
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
async function parseServerResponse(response) {
|
|
71
|
-
try {
|
|
72
|
-
const responseBody = await response.json();
|
|
73
|
-
return {
|
|
74
|
-
success: true,
|
|
75
|
-
data: responseBody
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
const causedByMessage = error instanceof Error ? `: ${error.message}` : '';
|
|
80
|
-
return {
|
|
81
|
-
success: false,
|
|
82
|
-
errorDetails: {
|
|
83
|
-
type: 'server',
|
|
84
|
-
statusCode: response.status,
|
|
85
|
-
message: `Failed to parse response body${causedByMessage}`
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function parseResponseData(schema, data) {
|
|
91
|
-
const dataParseResult = safeParse(schema, data);
|
|
92
|
-
if (dataParseResult.success) {
|
|
93
|
-
return {
|
|
94
|
-
success: true,
|
|
95
|
-
data: dataParseResult.data
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
success: false,
|
|
100
|
-
errorDetails: {
|
|
101
|
-
type: 'validation',
|
|
102
|
-
message: 'GraphQL response data doesn’t match the expected schema',
|
|
103
|
-
issues: dataParseResult.error.issues
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
114
|
async function fetchGraphqlEndpoint(options, payload) {
|
|
108
115
|
const baseRequestOptions = buildBaseRequestOptions(options);
|
|
109
116
|
try {
|
|
@@ -127,42 +134,53 @@ export function createClientFactory(dependencies) {
|
|
|
127
134
|
return mapUnknownNetworkErrorToFailureResult(error, baseRequestOptions.timeout);
|
|
128
135
|
}
|
|
129
136
|
}
|
|
130
|
-
async function
|
|
131
|
-
const payload = prepareRequestPayload(schema, operationType, options);
|
|
137
|
+
async function fetchAndParse(schema, options, payload) {
|
|
132
138
|
const serverResponseParseResult = await fetchGraphqlEndpoint(options, payload);
|
|
133
|
-
if (serverResponseParseResult.success) {
|
|
134
|
-
|
|
135
|
-
if (graphqlResponseParseResult.success) {
|
|
136
|
-
return parseResponseData(schema, graphqlResponseParseResult.data);
|
|
137
|
-
}
|
|
138
|
-
return graphqlResponseParseResult;
|
|
139
|
+
if (!serverResponseParseResult.success) {
|
|
140
|
+
return serverResponseParseResult;
|
|
139
141
|
}
|
|
140
|
-
return serverResponseParseResult;
|
|
142
|
+
return parseAndValidate(schema, serverResponseParseResult.data);
|
|
141
143
|
}
|
|
142
|
-
async function
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
async function performPersistedQueryOperation(schema, options, basePayload) {
|
|
145
|
+
const hashOnlyPayload = toPersistedQueryPayload(basePayload, 'hash-only');
|
|
146
|
+
const firstAttempt = await fetchGraphqlEndpoint(options, hashOnlyPayload);
|
|
147
|
+
if (!firstAttempt.success) {
|
|
148
|
+
return firstAttempt;
|
|
149
|
+
}
|
|
150
|
+
const retryReason = detectPersistedQueryRetryReason(firstAttempt.data);
|
|
151
|
+
if (retryReason === undefined) {
|
|
152
|
+
return parseAndValidate(schema, firstAttempt.data);
|
|
153
|
+
}
|
|
154
|
+
const retryPayload = retryReason === 'not-supported' ?
|
|
155
|
+
basePayload :
|
|
156
|
+
toPersistedQueryPayload(basePayload, 'hash-and-query');
|
|
157
|
+
return fetchAndParse(schema, options, retryPayload);
|
|
147
158
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (result.success) {
|
|
153
|
-
return result.data;
|
|
154
|
-
}
|
|
155
|
-
throw new GraphqlOperationError(result.errorDetails);
|
|
156
|
-
},
|
|
157
|
-
mutate,
|
|
158
|
-
async mutateOrThrow(schema, options) {
|
|
159
|
-
const result = await mutate(schema, options);
|
|
160
|
-
if (result.success) {
|
|
161
|
-
return result.data;
|
|
162
|
-
}
|
|
163
|
-
throw new GraphqlOperationError(result.errorDetails);
|
|
159
|
+
async function performOperation(operationType, handle, valuesOrOptions, maybeOptions) {
|
|
160
|
+
const resolution = resolveOperationInputs(handle, valuesOrOptions, maybeOptions);
|
|
161
|
+
if (!resolution.success) {
|
|
162
|
+
return resolution;
|
|
164
163
|
}
|
|
165
|
-
|
|
164
|
+
const inputs = resolution.data;
|
|
165
|
+
const payload = buildOperationPayload(toBuildPayloadInput(operationType, inputs));
|
|
166
|
+
if (clientOptions.persistedQueries === true) {
|
|
167
|
+
return performPersistedQueryOperation(inputs.schema, inputs.options, payload);
|
|
168
|
+
}
|
|
169
|
+
return fetchAndParse(inputs.schema, inputs.options, payload);
|
|
170
|
+
}
|
|
171
|
+
async function query(handle, ...rest) {
|
|
172
|
+
return performOperation('query', handle, rest[0], rest[1]);
|
|
173
|
+
}
|
|
174
|
+
async function mutate(handle, ...rest) {
|
|
175
|
+
return performOperation('mutation', handle, rest[0], rest[1]);
|
|
176
|
+
}
|
|
177
|
+
async function queryOrThrow(handle, ...rest) {
|
|
178
|
+
return extractDataOrThrow(await query(handle, ...rest));
|
|
179
|
+
}
|
|
180
|
+
async function mutateOrThrow(handle, ...rest) {
|
|
181
|
+
return extractDataOrThrow(await mutate(handle, ...rest));
|
|
182
|
+
}
|
|
183
|
+
return { query, queryOrThrow, mutate, mutateOrThrow };
|
|
166
184
|
};
|
|
167
185
|
}
|
|
168
186
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../source/zod-graphql-client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,YAAY,EAAE,MAAM,IAAI,CAAC;AAErF,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../source/zod-graphql-client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,YAAY,EAAE,MAAM,IAAI,CAAC;AAErF,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AA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C;QAED,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;IAC1D,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type SafeParseResult } from '@schema-hub/zod-error-formatter';
|
|
2
|
+
import { type GraphqlVariablePlaceholder } from '@schema-hub/zod-graphql-query-builder/zod-graphql-query-builder/values/variable-placeholder.d.ts';
|
|
3
|
+
import { type EntryValueType, type VariableEntry } from './variable-entry.js';
|
|
4
|
+
export type VariableValues<Map extends Record<string, VariableEntry>> = {
|
|
5
|
+
[Name in keyof Map]: EntryValueType<Map[Name]>;
|
|
6
|
+
};
|
|
7
|
+
declare const variableMapMetadataKey: unique symbol;
|
|
8
|
+
type AnyVariableMapMetadata = {
|
|
9
|
+
readonly definitions: Readonly<Record<string, string>>;
|
|
10
|
+
readonly parse: (input: unknown) => SafeParseResult<Record<string, unknown>>;
|
|
11
|
+
};
|
|
12
|
+
type VariableMapMetadata<Map extends Record<string, VariableEntry>> = {
|
|
13
|
+
readonly definitions: Readonly<Record<string, string>>;
|
|
14
|
+
readonly parse: (input: unknown) => SafeParseResult<VariableValues<Map>>;
|
|
15
|
+
};
|
|
16
|
+
declare const variableMapHandleBrand: unique symbol;
|
|
17
|
+
export type AnyVariableMapHandle = {
|
|
18
|
+
readonly [variableMapHandleBrand]?: true;
|
|
19
|
+
readonly [variableMapMetadataKey]: AnyVariableMapMetadata;
|
|
20
|
+
};
|
|
21
|
+
export type MaybeVariables = AnyVariableMapHandle | undefined;
|
|
22
|
+
export type VariableMapHandle<Map extends Record<string, VariableEntry>> = AnyVariableMapHandle & Readonly<Record<string & keyof Map, GraphqlVariablePlaceholder>> & {
|
|
23
|
+
readonly [variableMapMetadataKey]: VariableMapMetadata<Map>;
|
|
24
|
+
};
|
|
25
|
+
type MapOfHandle<Handle> = Handle extends VariableMapHandle<infer Map> ? Map : never;
|
|
26
|
+
export type ValuesOfVariableMapHandle<Handle extends AnyVariableMapHandle> = VariableValues<MapOfHandle<Handle>>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=define-variables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-variables.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-client/define-variables.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM;AAChD,EADqF,CAAC,IAC/E,EACH,KAAK,0BAA0B,EAElC,MAAM,6DAA6D,CAAC;AAErE,OAAO,EACH,KAAK,cAAc,EAGnB,KAAK,aAAa,EACrB,MAAM,qBAAqB;AAE5B,MAAM,MAAM,cAAc,CAAC,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,IAAI;KACnE,IAAI,IAAI,MAAM,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;CACjD;AAED,QAAA,MAAM,sBAAsB,eAAkC;AAE9D,KAAK,sBAAsB,GAAG;IAC1B,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACvD,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAChF;AAED,KAAK,mBAAmB,CAAC,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,IAAI;IAClE,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACvD,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,eAAe,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;CAC5E;AAED,OAAO,CAAC,MAAM,sBAAsB,EAAE,OAAO,MAAM;AAEnD,MAAM,MAAM,oBAAoB,GAAG;IAC/B,QAAQ,CAAC,CAAC,sBAAsB,CAAC,CAAC,EAAE,IAAI,CAAC;IACzC,QAAQ,CAAC,CAAC,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;CAC7D;AAED,MAAM,MAAM,cAAc,GAAG,oBAAoB,GAAG,SAAS;AAE7D,MAAM,MAAM,iBAAiB,CAAC,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,IACjE,oBAAoB,GACpB,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,EAAE,0BAA0B,CAAC,CAAC,GAChE;IACE,QAAQ,CAAC,CAAC,sBAAsB,CAAC,EAAE,mBAAmB,CAAC,GAAG,CAAC,CAAC;CAC/D;AAEL,KAAK,WAAW,CAAC,MAAM,IAAI,MAAM,SAAS,iBAAiB,CAAC,MAAM,GAAG,CAAC,GAAG,GAAG,GAAG,KAAK;AAEpF,MAAM,MAAM,yBAAyB,CAAC,MAAM,SAAS,oBAAoB,IAAI,cAAc,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod/v4-mini';
|
|
2
|
+
import { safeParse } from '@schema-hub/zod-error-formatter';
|
|
3
|
+
import { variablePlaceholder } from '@schema-hub/zod-graphql-query-builder/zod-graphql-query-builder/values/variable-placeholder.js';
|
|
4
|
+
import { inferGraphqlType } from './infer-graphql-type.js';
|
|
5
|
+
import { getEntrySchema, isExplicitVariableEntry } from './variable-entry.js';
|
|
6
|
+
const variableMapMetadataKey = Symbol('variable-map-metadata');
|
|
7
|
+
export function getVariableMapMetadata(handle) {
|
|
8
|
+
return handle[variableMapMetadataKey];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=define-variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-variables.js","sourceRoot":"","sources":["../../../../source/zod-graphql-client/define-variables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa;AAE/B,OAAO,EAAE,SAAS,EAAwB,MAAM;AAChD,EADqF,CAAC,IAC/E,EAEH,mBAAmB,EACtB,MAAM,6DAA6D,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB;AAC1D,OAAO,EAEH,cAAc,EACd,uBAAuB,EAE1B,MAAM,qBAAqB;AAM5B,MAAM,sBAAsB,GAAG,MAAM,CAAC,uBAAuB,CAAC;AAgC9D,MAAM,UAAU,sBAAsB,CAAC,MAA4B;IAC/D,OAAO,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAC1C"}
|
|
@@ -4,10 +4,18 @@ export type GraphqlClientOptions = ClientOptions & {
|
|
|
4
4
|
readonly fetch?: KyOptions['fetch'];
|
|
5
5
|
};
|
|
6
6
|
export declare function createGraphqlClient(clientOptions: GraphqlClientOptions): GraphqlClient;
|
|
7
|
-
export type { QuerySchema } from '@schema-hub/zod-graphql-query-builder
|
|
8
|
-
export { customScalar, enumValue, graphqlFieldOptions
|
|
9
|
-
export type { GraphqlClient
|
|
10
|
-
export type {
|
|
7
|
+
export type { QuerySchema } from '@schema-hub/zod-graphql-query-builder';
|
|
8
|
+
export { customScalar, enumValue, graphqlFieldOptions } from '@schema-hub/zod-graphql-query-builder';
|
|
9
|
+
export type { GraphqlClient } from './client.js';
|
|
10
|
+
export type { AnyVariableMapHandle, ValuesOfVariableMapHandle, VariableMapHandle, VariableValues } from './define-variables.js';
|
|
11
|
+
export { defineVariables } from './define-variables.js';
|
|
12
|
+
export type { GraphqlTypeInferenceError } from './infer-graphql-type.js';
|
|
13
|
+
export type { GraphqlError, OperationErrorDetails } from './operation-error.js';
|
|
11
14
|
export { GraphqlOperationError } from './operation-error.js';
|
|
15
|
+
export type { OperationHandle, OperationKind, ValuesOfOperationHandle } from './operation-handle.js';
|
|
16
|
+
export { defineMutation, defineQuery } from './operation-handle.js';
|
|
17
|
+
export type { GraphqlOverHttpOperationRequestPayload } from './operation-payload.js';
|
|
12
18
|
export type { OperationResult } from './operation-result.js';
|
|
19
|
+
export type { ExplicitVariableEntry, VariableEntry } from './variable-entry.js';
|
|
20
|
+
export { variable } from './variable-entry.js';
|
|
13
21
|
//# sourceMappingURL=entry-point.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-point.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-client/entry-point.ts"],"names":[],"mappings":"AAAA,OAAe,EAAE,KAAK,OAAO,IAAI,SAAS,EAAE,MAAM,IAAI,CAAC;AACvD,OAAO,EAAE,KAAK,aAAa,EAAuB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAE1F,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG;IAC/C,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;CACvC,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,oBAAoB,GAAG,aAAa,CAMtF;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAC/E,OAAO,
|
|
1
|
+
{"version":3,"file":"entry-point.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-client/entry-point.ts"],"names":[],"mappings":"AAAA,OAAe,EAAE,KAAK,OAAO,IAAI,SAAS,EAAE,MAAM,IAAI,CAAC;AACvD,OAAO,EAAE,KAAK,aAAa,EAAuB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAE1F,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG;IAC/C,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;CACvC,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,oBAAoB,GAAG,aAAa,CAMtF;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAC3G,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,YAAY,EACR,oBAAoB,EACpB,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACzE,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACrG,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpE,YAAY,EAAE,sCAAsC,EAAE,MAAM,wBAAwB,CAAC;AACrF,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,YAAY,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -6,6 +6,9 @@ export function createGraphqlClient(clientOptions) {
|
|
|
6
6
|
const createClient = createClientFactory({ ky });
|
|
7
7
|
return createClient(remainingOptions);
|
|
8
8
|
}
|
|
9
|
-
export { customScalar, enumValue, graphqlFieldOptions
|
|
9
|
+
export { customScalar, enumValue, graphqlFieldOptions } from '@schema-hub/zod-graphql-query-builder';
|
|
10
|
+
export { defineVariables } from './define-variables.js';
|
|
10
11
|
export { GraphqlOperationError } from './operation-error.js';
|
|
12
|
+
export { defineMutation, defineQuery } from './operation-handle.js';
|
|
13
|
+
export { variable } from './variable-entry.js';
|
|
11
14
|
//# sourceMappingURL=entry-point.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-point.js","sourceRoot":"","sources":["../../../../source/zod-graphql-client/entry-point.ts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E,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIpE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod/v4-mini';
|
|
2
|
+
export declare const graphqlErrorSchema: z.ZodMiniObject<{
|
|
3
|
+
message: z.ZodMiniString<string>;
|
|
4
|
+
locations: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
|
|
5
|
+
line: z.ZodMiniNumber<number>;
|
|
6
|
+
column: z.ZodMiniNumber<number>;
|
|
7
|
+
}, z.core.$strict>>>;
|
|
8
|
+
path: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniNumber<number>]>>>;
|
|
9
|
+
extensions: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export type GraphqlError = z.infer<typeof graphqlErrorSchema>;
|
|
12
|
+
//# sourceMappingURL=graphql-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-error.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-client/graphql-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAUhC,eAAO,MAAM,kBAAkB;;;;;;;;iBAMzB,CAAC;AAEP,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod/v4-mini';
|
|
2
|
-
import { mapTuple } from '@schema-hub/zod-error-formatter/tuple/non-empty-array.js';
|
|
3
2
|
const locationSchema = z
|
|
4
3
|
.strictObject({
|
|
5
4
|
line: z.number().check(z.int(), z.positive()),
|
|
@@ -10,40 +9,7 @@ export const graphqlErrorSchema = z
|
|
|
10
9
|
.object({
|
|
11
10
|
message: z.string(),
|
|
12
11
|
locations: z.optional(z.array(locationSchema)),
|
|
13
|
-
path: z.optional(z.array(pathSegmentSchema))
|
|
12
|
+
path: z.optional(z.array(pathSegmentSchema)),
|
|
13
|
+
extensions: z.optional(z.record(z.string(), z.unknown()))
|
|
14
14
|
});
|
|
15
|
-
function formatLocations(locations) {
|
|
16
|
-
if (locations === undefined) {
|
|
17
|
-
return '';
|
|
18
|
-
}
|
|
19
|
-
const [firstLocation] = locations;
|
|
20
|
-
if (firstLocation === undefined) {
|
|
21
|
-
return '';
|
|
22
|
-
}
|
|
23
|
-
return `${firstLocation.line}:${firstLocation.column}`;
|
|
24
|
-
}
|
|
25
|
-
function formatPath(path) {
|
|
26
|
-
return path === undefined ? '' : path.join('.');
|
|
27
|
-
}
|
|
28
|
-
function formatPrefix(error) {
|
|
29
|
-
const formattedPath = formatPath(error.path);
|
|
30
|
-
const formattedLocation = formatLocations(error.locations);
|
|
31
|
-
if (formattedPath.length > 0 && formattedLocation.length > 0) {
|
|
32
|
-
return `Error at ${formattedPath}:${formattedLocation} - `;
|
|
33
|
-
}
|
|
34
|
-
if (formattedPath.length > 0) {
|
|
35
|
-
return `Error at ${formattedPath} - `;
|
|
36
|
-
}
|
|
37
|
-
if (formattedLocation.length > 0) {
|
|
38
|
-
return `Error at ${formattedLocation} - `;
|
|
39
|
-
}
|
|
40
|
-
return '';
|
|
41
|
-
}
|
|
42
|
-
function formatGraphqlError(error) {
|
|
43
|
-
const prefix = formatPrefix(error);
|
|
44
|
-
return `${prefix}${error.message}`;
|
|
45
|
-
}
|
|
46
|
-
export function formatAllErrors(errors) {
|
|
47
|
-
return mapTuple(errors, formatGraphqlError);
|
|
48
|
-
}
|
|
49
15
|
//# sourceMappingURL=graphql-error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql-error.js","sourceRoot":"","sources":["../../../../source/zod-graphql-client/graphql-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"graphql-error.js","sourceRoot":"","sources":["../../../../source/zod-graphql-client/graphql-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAEhC,MAAM,cAAc,GAAG,CAAC;KACnB,YAAY,CAAC;IACV,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC7C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;CAClD,CAAC,CAAC;AAEP,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAE5D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC;KAC9B,MAAM,CAAC;IACJ,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAC9C,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC5C,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;CAC5D,CAAC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
2
|
import { isNonEmptyArray } from '@schema-hub/zod-error-formatter/tuple/non-empty-array.js';
|
|
3
|
-
import { safeParse } from '@schema-hub/zod-error-formatter
|
|
4
|
-
import {
|
|
3
|
+
import { safeParse } from '@schema-hub/zod-error-formatter';
|
|
4
|
+
import { graphqlErrorSchema } from './graphql-error.js';
|
|
5
5
|
const graphqlResponseSchema = z
|
|
6
6
|
.object({
|
|
7
7
|
data: z.unknown(),
|
|
@@ -18,7 +18,7 @@ export function parseGraphqlResponse(responseBody) {
|
|
|
18
18
|
errorDetails: {
|
|
19
19
|
type: 'graphql',
|
|
20
20
|
message: 'GraphQL response contains errors',
|
|
21
|
-
errors
|
|
21
|
+
errors
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql-response.js","sourceRoot":"","sources":["../../../../source/zod-graphql-client/graphql-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAChE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"graphql-response.js","sourceRoot":"","sources":["../../../../source/zod-graphql-client/graphql-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,MAAM,qBAAqB,GAAG,CAAC;KAC1B,MAAM,CAAC;IACJ,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE;IACjB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,QAAQ,EAAE;CACjD,CAAC;KACD,KAAK,EAAE,CAAC;AAEb,MAAM,UAAU,oBAAoB,CAAC,YAAqB;IACtD,MAAM,0BAA0B,GAAG,SAAS,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC;IAElF,IAAI,0BAA0B,CAAC,OAAO,EAAE,CAAC;QACrC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,0BAA0B,CAAC,IAAI,CAAC;QAEzD,IAAI,MAAM,KAAK,SAAS,IAAI,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;YAClD,OAAO;gBACH,OAAO,EAAE,KAAK;gBACd,YAAY,EAAE;oBACV,IAAI,EAAE,SAAS;oBACf,OAAO,EAAE,kCAAkC;oBAC3C,MAAM;iBACT;aACJ,CAAC;QACN,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACnC,CAAC;IAED,OAAO;QACH,OAAO,EAAE,KAAK;QACd,YAAY,EAAE;YACV,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,2DAA2D;SACvE;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer-graphql-type.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-client/infer-graphql-type.ts"],"names":[],"mappings":"AACA,OAAO,EAOH,KAAK,QAAQ,EAChB,MAAM,aAAa"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle -- we need to access _zod */
|
|
2
|
+
import { $ZodArray, $ZodBoolean, $ZodNullable, $ZodNumber, $ZodOptional, $ZodString } from 'zod/v4/core';
|
|
3
|
+
export class GraphqlTypeInferenceError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
// eslint-disable-next-line functional/no-this-expressions -- sub-classing errors is one of the few exceptions where classes are useful
|
|
7
|
+
this.name = 'GraphqlTypeInferenceError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const integerNumberFormats = new Set(['safeint', 'int32', 'int64', 'uint32', 'uint64']);
|
|
11
|
+
function hasIntegerFormat(schema) {
|
|
12
|
+
const def = schema._zod.def;
|
|
13
|
+
if (def.format !== undefined && integerNumberFormats.has(def.format)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
const { checks = [] } = def;
|
|
17
|
+
return checks.some((check) => {
|
|
18
|
+
const checkFormat = check._zod.def.format;
|
|
19
|
+
return checkFormat !== undefined && integerNumberFormats.has(checkFormat);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function unwrapNullable(schema) {
|
|
23
|
+
let current = schema;
|
|
24
|
+
let isNullable = false;
|
|
25
|
+
while (current instanceof $ZodNullable || current instanceof $ZodOptional) {
|
|
26
|
+
current = current._zod.def.innerType;
|
|
27
|
+
isNullable = true;
|
|
28
|
+
}
|
|
29
|
+
return { innerSchema: current, isNullable };
|
|
30
|
+
}
|
|
31
|
+
export function inferGraphqlType(schema) {
|
|
32
|
+
const { innerSchema, isNullable } = unwrapNullable(schema);
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define -- mutual recursion via arrays
|
|
34
|
+
const nonNullType = inferNonNullType(innerSchema);
|
|
35
|
+
return isNullable ? nonNullType : `${nonNullType}!`;
|
|
36
|
+
}
|
|
37
|
+
function inferPrimitiveType(schema) {
|
|
38
|
+
if (schema instanceof $ZodString) {
|
|
39
|
+
return 'String';
|
|
40
|
+
}
|
|
41
|
+
if (schema instanceof $ZodBoolean) {
|
|
42
|
+
return 'Boolean';
|
|
43
|
+
}
|
|
44
|
+
if (schema instanceof $ZodNumber) {
|
|
45
|
+
return hasIntegerFormat(schema) ? 'Int' : 'Float';
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
function inferNonNullType(schema) {
|
|
50
|
+
if (schema instanceof $ZodArray) {
|
|
51
|
+
return `[${inferGraphqlType(schema._zod.def.element)}]`;
|
|
52
|
+
}
|
|
53
|
+
const primitiveType = inferPrimitiveType(schema);
|
|
54
|
+
if (primitiveType !== null) {
|
|
55
|
+
return primitiveType;
|
|
56
|
+
}
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define -- thrown only after the early-return paths are exhausted
|
|
58
|
+
throw new GraphqlTypeInferenceError(buildInferenceErrorMessage(schema._zod.def.type));
|
|
59
|
+
}
|
|
60
|
+
function buildInferenceErrorMessage(kind) {
|
|
61
|
+
return [
|
|
62
|
+
`Cannot infer a GraphQL type for Zod schema of kind "${kind}".`,
|
|
63
|
+
'Use variable(type, schema) to declare the GraphQL type explicitly.'
|
|
64
|
+
]
|
|
65
|
+
.join(' ');
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=infer-graphql-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer-graphql-type.js","sourceRoot":"","sources":["../../../../source/zod-graphql-client/infer-graphql-type.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,OAAO,EACH,SAAS,EACT,WAAW,EACX,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,UAAU,EAEb,MAAM,aAAa,CAAC;AAErB,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAChD,YAAmB,OAAe;QAC9B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,uIAAuI;QACvI,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC5C,CAAC;CACJ;AAED,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AAOxF,SAAS,gBAAgB,CAAC,MAAkB;IACxC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAqB,CAAC;IAC9C,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QACnE,OAAO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AM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC;IACtD,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAgB;IACtC,IAAI,MAAM,YAAY,SAAS,EAAE,CAAC;QAC9B,OAAO,IAAI,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;IAC5D,CAAC;IACD,MAAM,aAAa,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACjD,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;QACzB,OAAO,aAAa,CAAC;IACzB,CAAC;IACD,6HAA6H;IAC7H,MAAM,IAAI,yBAAyB,CAAC,0BAA0B,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAC1F,CAAC;AAED,SAAS,0BAA0B,CAAC,IAAY;IAC5C,OAAO;QACH,uDAAuD,IAAI,IAAI;QAC/D,oEAAoE;KACvE;SACI,IAAI,CAAC,GAAG,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import type { NonEmptyArray } from '@schema-hub/zod-error-formatter/tuple/non-empty-array.
|
|
1
|
+
import type { NonEmptyArray } from '@schema-hub/zod-error-formatter/tuple/non-empty-array.d.ts';
|
|
2
|
+
import type { GraphqlError } from './graphql-error.js';
|
|
3
|
+
export type { GraphqlError } from './graphql-error.js';
|
|
2
4
|
type BaseError = {
|
|
3
5
|
message: string;
|
|
4
6
|
};
|
|
5
7
|
type GraphqlResponseError = BaseError & {
|
|
6
8
|
type: 'graphql';
|
|
7
|
-
errors: NonEmptyArray<
|
|
9
|
+
errors: NonEmptyArray<GraphqlError>;
|
|
8
10
|
};
|
|
9
11
|
type ServerError = BaseError & {
|
|
10
12
|
type: 'server';
|
|
11
13
|
statusCode: number;
|
|
14
|
+
cause?: unknown;
|
|
12
15
|
};
|
|
13
16
|
type ValidationError = BaseError & {
|
|
14
17
|
type: 'validation';
|
|
@@ -16,14 +19,11 @@ type ValidationError = BaseError & {
|
|
|
16
19
|
};
|
|
17
20
|
type NetworkError = BaseError & {
|
|
18
21
|
type: 'network';
|
|
22
|
+
cause?: unknown;
|
|
19
23
|
};
|
|
20
24
|
type UnknownError = BaseError & {
|
|
21
25
|
type: 'unknown';
|
|
26
|
+
cause?: unknown;
|
|
22
27
|
};
|
|
23
28
|
export type OperationErrorDetails = GraphqlResponseError | NetworkError | ServerError | UnknownError | ValidationError;
|
|
24
|
-
export declare class GraphqlOperationError extends Error {
|
|
25
|
-
readonly details: Omit<OperationErrorDetails, 'message'>;
|
|
26
|
-
constructor(details: OperationErrorDetails);
|
|
27
|
-
}
|
|
28
|
-
export {};
|
|
29
29
|
//# sourceMappingURL=operation-error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-error.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-client/operation-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"operation-error.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-client/operation-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB;AAEtD,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB;AAEtD,KAAK,SAAS,GAAG;IACb,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,KAAK,oBAAoB,GAAG,SAAS,GAAG;IACpC,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;CACvC;AAED,KAAK,WAAW,GAAG,SAAS,GAAG;IAC3B,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,KAAK,eAAe,GAAG,SAAS,GAAG;IAC/B,IAAI,EAAE,YAAY,CAAC;IACnB,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACjC;AAED,KAAK,YAAY,GAAG,SAAS,GAAG;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,KAAK,YAAY,GAAG,SAAS,GAAG;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,MAAM,qBAAqB,GAAG,oBAAoB,GAAG,YAAY,GAAG,WAAW,GAAG,YAAY,GAAG,eAAe"}
|