Skip to content

Commit 76b6a03

Browse files
github-actions[bot]mvantellingen
authored andcommitted
update version (next)
1 parent 3dc1d79 commit 76b6a03

9 files changed

+100
-86
lines changed

.changeset/pre.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"changesets": [
88
"beige-donuts-attend",
99
"five-weeks-talk",
10-
"tough-grapes-hug"
10+
"tough-grapes-hug",
11+
"warm-tomatoes-wonder"
1112
]
1213
}

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @labdigital/react-query-opal
22

3+
## 2.0.0-next.3
4+
5+
### Major Changes
6+
7+
- 3dc1d79: Internal refactor to better support persisted operations / trusted documents
8+
39
## 1.5.0-next.2
410

511
### Patch Changes

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@labdigital/graphql-fetcher",
3-
"version": "1.5.0-next.2",
3+
"version": "2.0.0-next.3",
44
"description": "Custom fetcher for react-query to use with @labdigital/node-federated-token",
55
"type": "module",
66
"main": "./dist/index.cjs",

src/client.test.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ describe("gqlClientFetch", () => {
5656
body: JSON.stringify({
5757
query: query,
5858
variables: { myVar: "baz" },
59-
extensions: { persistedQuery: {
60-
version: 1,
61-
sha256Hash: await createSha256(query.toString()),
62-
}},
59+
extensions: {
60+
persistedQuery: {
61+
version: 1,
62+
sha256Hash: await createSha256(query.toString()),
63+
},
64+
},
6365
}),
6466
// Method was post:
6567
method: "POST",
@@ -242,10 +244,12 @@ describe("gqlClientFetch", () => {
242244
body: JSON.stringify({
243245
query: query,
244246
variables: { myVar: "baz" },
245-
extensions: { persistedQuery: {
246-
version: 1,
247-
sha256Hash: await createSha256(query.toString()),
248-
}},
247+
extensions: {
248+
persistedQuery: {
249+
version: 1,
250+
sha256Hash: await createSha256(query.toString()),
251+
},
252+
},
249253
}),
250254
// Method was post:
251255
method: "POST",

src/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Options = {
4141
*/
4242
defaultHeaders?: Headers | Record<string, string>;
4343

44-
mode?: ModeFlags
44+
mode?: ModeFlags;
4545

4646
/**
4747
* Function to customize creating the documentId from a query

src/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ export interface NextFetchRequestConfig {
5656
}
5757

5858
export const pruneObject = <T>(object: T): Partial<T> => {
59-
const data: Record<string, unknown> = {}
59+
const data: Record<string, unknown> = {};
6060
for (const key in object) {
6161
if (isNotEmpty(object[key])) {
6262
data[key] = object[key];
6363
}
6464
}
6565
return JSON.parse(JSON.stringify(data ?? null));
66-
}
66+
};
6767

6868
const isNotEmpty = (value: unknown) => value && Object.keys(value).length > 0;
6969

src/request.test.ts

+34-48
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,42 @@ it.each(["both", "document", "persistent"])(
1818
documentId: "123",
1919
} as GraphQLRequest<Record<string, unknown>>);
2020

21-
const result: Record<string, unknown> = {}
21+
const result: Record<string, unknown> = {};
2222
data.forEach((value, key) => {
23-
result[key] = value
24-
})
23+
result[key] = value;
24+
});
2525

2626
switch (mode) {
2727
case "both": {
28-
expect(result).toStrictEqual(
29-
{
30-
documentId: "123",
31-
op: "hello",
32-
variables: '{"name":"world"}',
33-
extensions: '{"persistedQuery":{"version":1,"sha256Hash":"123"}}',
34-
},
35-
);
28+
expect(result).toStrictEqual({
29+
documentId: "123",
30+
op: "hello",
31+
variables: '{"name":"world"}',
32+
extensions: '{"persistedQuery":{"version":1,"sha256Hash":"123"}}',
33+
});
3634
break;
3735
}
3836
case "persisted": {
39-
expect(result).toStrictEqual(
40-
{
41-
documentId: "123",
42-
op: "hello",
43-
variables: '{"name":"world"}',
44-
extensions: '{"persistedQuery":{"version":1,"sha256Hash":"123"}}',
45-
}
46-
);
37+
expect(result).toStrictEqual({
38+
documentId: "123",
39+
op: "hello",
40+
variables: '{"name":"world"}',
41+
extensions: '{"persistedQuery":{"version":1,"sha256Hash":"123"}}',
42+
});
4743
break;
4844
}
4945
case "document": {
50-
expect(result).toStrictEqual(
51-
{
52-
op: "hello",
53-
variables: '{"name":"world"}',
54-
extensions: '{"persistedQuery":{"version":1,"sha256Hash":"123"}}',
55-
}
56-
);
46+
expect(result).toStrictEqual({
47+
op: "hello",
48+
variables: '{"name":"world"}',
49+
extensions: '{"persistedQuery":{"version":1,"sha256Hash":"123"}}',
50+
});
5751
break;
5852
}
5953
}
6054
},
6155
);
6256

63-
6457
it.each(["both", "document", "persistent"])(
6558
"createRequestURL - minimal mode=%s",
6659
(mode) => {
@@ -72,39 +65,32 @@ it.each(["both", "document", "persistent"])(
7265
documentId: "123",
7366
} as GraphQLRequest<Record<string, unknown>>);
7467

75-
const result: Record<string, unknown> = {}
68+
const result: Record<string, unknown> = {};
7669
data.forEach((value, key) => {
77-
result[key] = value
78-
})
70+
result[key] = value;
71+
});
7972

8073
switch (mode) {
8174
case "both": {
82-
expect(result).toStrictEqual(
83-
{
84-
documentId: "123",
85-
op: "hello",
86-
},
87-
);
75+
expect(result).toStrictEqual({
76+
documentId: "123",
77+
op: "hello",
78+
});
8879
break;
8980
}
9081
case "persisted": {
91-
expect(result).toStrictEqual(
92-
{
93-
documentId: "123",
94-
op: "hello",
95-
}
96-
);
82+
expect(result).toStrictEqual({
83+
documentId: "123",
84+
op: "hello",
85+
});
9786
break;
9887
}
9988
case "document": {
100-
expect(result).toStrictEqual(
101-
{
102-
op: "hello",
103-
}
104-
);
89+
expect(result).toStrictEqual({
90+
op: "hello",
91+
});
10592
break;
10693
}
10794
}
10895
},
10996
);
110-

src/server.test.ts

+28-21
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ describe("gqlServerFetch", () => {
8282
body: JSON.stringify({
8383
query: query.toString(),
8484
variables: { myVar: "baz" },
85-
extensions: { persistedQuery: {
86-
version: 1,
87-
sha256Hash: await createSha256(query.toString()),
88-
}},
85+
extensions: {
86+
persistedQuery: {
87+
version: 1,
88+
sha256Hash: await createSha256(query.toString()),
89+
},
90+
},
8991
}),
9092
headers: new Headers({
9193
"Content-Type": "application/json",
@@ -118,10 +120,12 @@ describe("gqlServerFetch", () => {
118120
body: JSON.stringify({
119121
query: queryMutation.toString(),
120122
variables: { myVar: "baz" },
121-
extensions: { persistedQuery: {
122-
version: 1,
123-
sha256Hash: await createSha256(queryMutation.toString()),
124-
}},
123+
extensions: {
124+
persistedQuery: {
125+
version: 1,
126+
sha256Hash: await createSha256(queryMutation.toString()),
127+
},
128+
},
125129
}),
126130
headers: new Headers({
127131
"Content-Type": "application/json",
@@ -199,7 +203,7 @@ describe("gqlServerFetch", () => {
199203
}),
200204
cache: "force-cache",
201205
next: { revalidate: 900 },
202-
signal: expect.any(AbortSignal)
206+
signal: expect.any(AbortSignal),
203207
},
204208
);
205209
});
@@ -218,18 +222,21 @@ describe("gqlServerFetch", () => {
218222

219223
expect(gqlResponse).toEqual(response);
220224
expect(mockedFetch).toHaveBeenCalledTimes(1);
221-
expect(mockedFetch).toHaveBeenCalledWith("https://localhost/graphql?op=myQuery", {
222-
method: "POST", // <- Note that when caching is disabled, the method is 'POST'
223-
body: JSON.stringify({
224-
query: query.toString(),
225-
variables: { myVar: "baz" },
226-
}),
227-
headers: new Headers({
228-
"Content-Type": "application/json",
229-
}),
230-
cache: "no-store",
231-
signal: expect.any(AbortSignal),
232-
});
225+
expect(mockedFetch).toHaveBeenCalledWith(
226+
"https://localhost/graphql?op=myQuery",
227+
{
228+
method: "POST", // <- Note that when caching is disabled, the method is 'POST'
229+
body: JSON.stringify({
230+
query: query.toString(),
231+
variables: { myVar: "baz" },
232+
}),
233+
headers: new Headers({
234+
"Content-Type": "application/json",
235+
}),
236+
cache: "no-store",
237+
signal: expect.any(AbortSignal),
238+
},
239+
);
233240
});
234241

235242
// This seems as if we test fetch itself but we're actually testing whether the fetcher properly propagates the fetch errors to the package consumers

src/server.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export const initServerFetcher =
146146
} catch (err: unknown) {
147147
span.setStatus({
148148
code: SpanStatusCode.ERROR,
149-
message: err instanceof Error ? err.message : String(err)
149+
message: err instanceof Error ? err.message : String(err),
150150
});
151151
throw err;
152152
}
@@ -168,7 +168,12 @@ export const initServerFetcher =
168168
if (!isPersistedQuery(request) && hasPersistedQueryError(response)) {
169169
// If the cached query doesn't exist, fall back to POST request and
170170
// let the server cache it.
171-
response = await gqlPost(url, request, { cache, next }, requestOptions);
171+
response = await gqlPost(
172+
url,
173+
request,
174+
{ cache, next },
175+
requestOptions,
176+
);
172177
}
173178

174179
span.end();
@@ -227,10 +232,15 @@ const gqlPersistedQuery = async <TVariables>(
227232
* @param response Fetch response object
228233
* @returns GraphQL response body
229234
*/
230-
const parseResponse = async (request: GraphQLRequest<unknown>, response: Response) => {
235+
const parseResponse = async (
236+
request: GraphQLRequest<unknown>,
237+
response: Response,
238+
) => {
231239
invariant(
232240
response.ok,
233-
errorMessage(`Response for ${request.operationName} errored: ${response.status} ${response.statusText}`),
241+
errorMessage(
242+
`Response for ${request.operationName} errored: ${response.status} ${response.statusText}`,
243+
),
234244
);
235245

236246
return await response.json();

0 commit comments

Comments
 (0)