@vladimirdev635/gql-client 0.0.75 → 0.0.77
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
CHANGED
package/serializers/json.js
CHANGED
|
@@ -3,7 +3,8 @@ export function createJSONSerializer() {
|
|
|
3
3
|
return {
|
|
4
4
|
serializeRequest: ({ operation, requestContext, variables }) => {
|
|
5
5
|
const headers = {
|
|
6
|
-
'Content-Type': 'application/json'
|
|
6
|
+
'Content-Type': 'application/json',
|
|
7
|
+
'GQL-Operation-Hash': operation.hash
|
|
7
8
|
};
|
|
8
9
|
if (operation.type === 'SUBSCRIPTION') {
|
|
9
10
|
headers.Accept = 'text/event-stream';
|
|
@@ -13,7 +14,7 @@ export function createJSONSerializer() {
|
|
|
13
14
|
method: 'POST',
|
|
14
15
|
body: JSON.stringify({
|
|
15
16
|
query: operation.document,
|
|
16
|
-
variables
|
|
17
|
+
variables: operation.variablesSchema.parse(variables)
|
|
17
18
|
}, (key, value) => {
|
|
18
19
|
assert(!(value instanceof File), 'jsonSerializer cannot encode File objects, ' +
|
|
19
20
|
`key: "${key}"`);
|
package/serializers/multipart.js
CHANGED
|
@@ -56,9 +56,16 @@ function buildFormData(operation, variables, shouldTreatAsObject) {
|
|
|
56
56
|
export function createMultipartSerializer() {
|
|
57
57
|
return {
|
|
58
58
|
serializeRequest: ({ operation, requestContext, variables }) => {
|
|
59
|
+
const headers = {
|
|
60
|
+
'GQL-Operation-Hash': operation.hash
|
|
61
|
+
};
|
|
62
|
+
if (operation.type === 'SUBSCRIPTION') {
|
|
63
|
+
headers.Accept = 'text/event-stream';
|
|
64
|
+
}
|
|
59
65
|
return {
|
|
60
66
|
method: 'POST',
|
|
61
|
-
|
|
67
|
+
headers,
|
|
68
|
+
body: buildFormData(operation, operation.variablesSchema.parse(variables)),
|
|
62
69
|
...requestContext.fetchOptions
|
|
63
70
|
};
|
|
64
71
|
},
|
|
@@ -12,7 +12,8 @@ describe('Json serializer', () => {
|
|
|
12
12
|
name: z.string(),
|
|
13
13
|
file: z.file(),
|
|
14
14
|
}),
|
|
15
|
-
resultSchema: z.void()
|
|
15
|
+
resultSchema: z.void(),
|
|
16
|
+
hash: ''
|
|
16
17
|
};
|
|
17
18
|
const variables = {
|
|
18
19
|
name: 'test-name',
|
|
@@ -33,7 +34,8 @@ describe('Json serializer', () => {
|
|
|
33
34
|
variablesSchema: z.object({
|
|
34
35
|
name: z.string(),
|
|
35
36
|
}),
|
|
36
|
-
resultSchema: z.void()
|
|
37
|
+
resultSchema: z.void(),
|
|
38
|
+
hash: ''
|
|
37
39
|
};
|
|
38
40
|
const variables = {
|
|
39
41
|
name: 'test-name',
|
|
@@ -12,7 +12,8 @@ describe('Multipart serializer', () => {
|
|
|
12
12
|
variablesSchema: z.object({
|
|
13
13
|
name: z.string()
|
|
14
14
|
}),
|
|
15
|
-
resultSchema: z.void()
|
|
15
|
+
resultSchema: z.void(),
|
|
16
|
+
hash: ''
|
|
16
17
|
};
|
|
17
18
|
const variables = {
|
|
18
19
|
name: 'test-name'
|
|
@@ -33,7 +34,8 @@ describe('Multipart serializer', () => {
|
|
|
33
34
|
name: z.string(),
|
|
34
35
|
file: z.file()
|
|
35
36
|
}),
|
|
36
|
-
resultSchema: z.void()
|
|
37
|
+
resultSchema: z.void(),
|
|
38
|
+
hash: ''
|
|
37
39
|
};
|
|
38
40
|
const variables = {
|
|
39
41
|
name: 'test-name',
|
package/types/base.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
-
export type
|
|
2
|
+
export type SchemaForInput<T> = z.ZodType<unknown, T>;
|
|
3
|
+
export type SchemaForOutput<T> = z.ZodType<T>;
|
|
3
4
|
interface BaseOperation<V, R> {
|
|
4
5
|
name: string;
|
|
5
6
|
document: string;
|
|
6
|
-
variablesSchema:
|
|
7
|
-
resultSchema:
|
|
7
|
+
variablesSchema: SchemaForInput<V>;
|
|
8
|
+
resultSchema: SchemaForOutput<R>;
|
|
9
|
+
hash: string;
|
|
8
10
|
}
|
|
9
11
|
export interface SyncOperation<V, R> extends BaseOperation<V, R> {
|
|
10
12
|
type: 'QUERY' | 'MUTATION';
|