Skip to content

Commit 1c8a036

Browse files
committed
Enable retries for test GQL queries
Previously queries weren't retried because it was a POST request, which is the HTTP equivalent of a GQL mutation. So this just adapts the defaults for GQL. Should fix the flaky file test which produces an ECONNRESET a lot.
1 parent a3cd3fa commit 1c8a036

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

test/utility/create-graphql-client.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ export const createGraphqlClient = async (
3333
let authToken = '';
3434

3535
const execute = <TData = AnyObject, TVars = AnyObject>(
36-
query: DocumentNode | string,
36+
doc: DocumentNode | string,
3737
variables?: TVars,
3838
) => {
39+
const query = typeof doc === 'string' ? doc : print(doc);
3940
const result = got
4041
.post({
4142
url: `${url}/graphql`,
@@ -44,9 +45,13 @@ export const createGraphqlClient = async (
4445
...(authToken ? { Authorization: `Bearer ${authToken}` } : {}),
4546
},
4647
json: {
47-
query: typeof query === 'string' ? query : print(query),
48+
query,
4849
variables,
4950
},
51+
retry: {
52+
// Retry queries, not mutations
53+
methods: query.trim().startsWith('query') ? ['POST'] : [],
54+
},
5055
})
5156
.json<ExecutionResult<TData>>()
5257
.then((result) => {

0 commit comments

Comments
 (0)