Skip to content

Commit 3b7b31f

Browse files
authored
fix: ensure code formatting is correct (#604)
1 parent 8c99d80 commit 3b7b31f

12 files changed

+39
-40
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const document = gql`
8181
}
8282
}
8383
`
84-
const endpoint = 'https://api.spacex.land/graphql/';
84+
const endpoint = 'https://api.spacex.land/graphql/'
8585
const client = new GraphQLClient(endpoint)
8686
await client.request(document)
8787
```

examples/configuration-request-json-serializer.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import JSONbig from 'json-bigint'
88

99
const jsonSerializer = JSONbig({ useNativeBigInt: true })
1010
const graphQLClient = new GraphQLClient(`https://some-api`, { jsonSerializer })
11-
const data = await graphQLClient.request<{ someBigInt: bigint }>(
12-
gql`
13-
{
14-
someBigInt
15-
}
16-
`
17-
)
11+
const data = await graphQLClient.request<{ someBigInt: bigint }>(gql`
12+
{
13+
someBigInt
14+
}
15+
`)
1816
console.log(typeof data.someBigInt) // if >MAX_SAFE_INTEGER then 'bigint' else 'number'

examples/other-middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const getAccessToken = () => Promise.resolve(`some special token here`)
5252
console.error(
5353
`[${traceId}] Request error:
5454
status ${response.status}
55-
details: ${response.errors.map((_) => _.message).join(`, `)}`
55+
details: ${response.errors.map((_) => _.message).join(`, `)}`,
5656
)
5757
}
5858
}

src/index.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const buildRequestConfig = <V extends Variables>(params: BuildRequestConfigParam
110110
})
111111
return acc
112112
},
113-
[]
113+
[],
114114
)
115115

116116
return `query=${encodeURIComponent(params_.jsonSerializer.stringify(payload))}`
@@ -179,7 +179,10 @@ const createHttpMethodFetcher =
179179
* GraphQL Client.
180180
*/
181181
class GraphQLClient {
182-
constructor(private url: string, public readonly requestConfig: RequestConfig = {}) {}
182+
constructor(
183+
private url: string,
184+
public readonly requestConfig: RequestConfig = {},
185+
) {}
183186

184187
/**
185188
* Send a GraphQL query to the server.
@@ -422,7 +425,7 @@ const makeRequest = async <T = unknown, V extends Variables = Variables>(params:
422425
throw new ClientError(
423426
// @ts-expect-error TODO
424427
{ ...errorResult, status: response.status, headers: response.headers },
425-
{ query, variables }
428+
{ query, variables },
426429
)
427430
}
428431
}
@@ -586,7 +589,7 @@ const createRequestBody = (
586589
query: string | string[],
587590
variables?: Variables | Variables[],
588591
operationName?: string,
589-
jsonSerializer?: JsonSerializer
592+
jsonSerializer?: JsonSerializer,
590593
): string => {
591594
const jsonSerializer_ = jsonSerializer ?? defaultJsonSerializer
592595
if (!Array.isArray(query)) {
@@ -603,15 +606,15 @@ const createRequestBody = (
603606
acc.push({ query: currentQuery, variables: variables ? variables[index] : undefined })
604607
return acc
605608
},
606-
[]
609+
[],
607610
)
608611

609612
return jsonSerializer_.stringify(payload)
610613
}
611614

612615
const getResult = async (
613616
response: Response,
614-
jsonSerializer: JsonSerializer
617+
jsonSerializer: JsonSerializer,
615618
): Promise<
616619
| { data: object; errors: undefined }[]
617620
| { data: object; errors: undefined }
@@ -659,7 +662,7 @@ const callOrIdentity = <T>(value: MaybeLazy<T>) => {
659662
export const gql = (chunks: TemplateStringsArray, ...variables: unknown[]): string => {
660663
return chunks.reduce(
661664
(acc, chunk, index) => `${acc}${chunk}${index in variables ? String(variables[index]) : ``}`,
662-
``
665+
``,
663666
)
664667
}
665668

src/parseArgs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
export const parseRequestArgs = <V extends Variables = Variables>(
1515
documentOrOptions: RequestDocument | RequestOptions<V>,
1616
variables?: V,
17-
requestHeaders?: GraphQLClientRequestHeaders
17+
requestHeaders?: GraphQLClientRequestHeaders,
1818
): RequestOptions<V> => {
1919
return (documentOrOptions as RequestOptions<V>).document
2020
? (documentOrOptions as RequestOptions<V>)
@@ -29,7 +29,7 @@ export const parseRequestArgs = <V extends Variables = Variables>(
2929
export const parseRawRequestArgs = <V extends Variables = Variables>(
3030
queryOrOptions: string | RawRequestOptions<V>,
3131
variables?: V,
32-
requestHeaders?: GraphQLClientRequestHeaders
32+
requestHeaders?: GraphQLClientRequestHeaders,
3333
): RawRequestOptions<V> => {
3434
return (queryOrOptions as RawRequestOptions<V>).query
3535
? (queryOrOptions as RawRequestOptions<V>)
@@ -43,7 +43,7 @@ export const parseRawRequestArgs = <V extends Variables = Variables>(
4343

4444
export const parseBatchRequestArgs = <V extends Variables = Variables>(
4545
documentsOrOptions: BatchRequestDocument<V>[] | BatchRequestsOptions<V>,
46-
requestHeaders?: GraphQLClientRequestHeaders
46+
requestHeaders?: GraphQLClientRequestHeaders,
4747
): BatchRequestsOptions<V> => {
4848
return (documentsOrOptions as BatchRequestsOptions<V>).documents
4949
? (documentsOrOptions as BatchRequestsOptions<V>)

src/resolveRequestDocument.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { RequestDocument } from './types.js'
22
/**
3-
* Refactored imports from `graphql` to be more specific, this helps import only the required files (100KiB)
3+
* Refactored imports from `graphql` to be more specific, this helps import only the required files (100KiB)
44
* instead of the entire package (>500KiB) where tree-shaking is not supported.
55
* @see https://github.com/jasonkuhrt/graphql-request/pull/543
66
*/
@@ -16,7 +16,7 @@ const extractOperationName = (document: DocumentNode): string | undefined => {
1616
let operationName = undefined
1717

1818
const operationDefinitions = document.definitions.filter(
19-
(definition) => definition.kind === `OperationDefinition`
19+
(definition) => definition.kind === `OperationDefinition`,
2020
) as OperationDefinitionNode[]
2121

2222
if (operationDefinitions.length === 1) {
@@ -27,7 +27,7 @@ const extractOperationName = (document: DocumentNode): string | undefined => {
2727
}
2828

2929
export const resolveRequestDocument = (
30-
document: RequestDocument
30+
document: RequestDocument,
3131
): { query: string; operationName?: string } => {
3232
if (typeof document === `string`) {
3333
let operationName = undefined

tests/__helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type MockResult<Spec extends MockSpec | MockSpecBatch = MockSpec> = {
4747
}
4848

4949
export const setupMockServer = <T extends MockSpec | MockSpecBatch = MockSpec>(
50-
delay?: number
50+
delay?: number,
5151
): Context<T> => {
5252
const ctx = {} as Context<T>
5353
beforeAll(async () => {

tests/batching.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test(`basic error`, async () => {
3838
})
3939

4040
await expect(batchRequests(mockServer.url, [{ document: `x` }])).rejects.toMatchInlineSnapshot(
41-
`[Error: GraphQL Error (Code: 200): {"response":{"0":{"errors":{"message":"Syntax Error GraphQL request (1:1) Unexpected Name \\"x\\"\\n\\n1: x\\n ^\\n","locations":[{"line":1,"column":1}]}},"status":200,"headers":{}},"request":{"query":["x"],"variables":[null]}}]`
41+
`[Error: GraphQL Error (Code: 200): {"response":{"0":{"errors":{"message":"Syntax Error GraphQL request (1:1) Unexpected Name \\"x\\"\\n\\n1: x\\n ^\\n","locations":[{"line":1,"column":1}]}},"status":200,"headers":{}},"request":{"query":["x"],"variables":[null]}}]`,
4242
)
4343
})
4444

@@ -61,9 +61,9 @@ test(`successful query with another which make an error`, async () => {
6161
})
6262

6363
await expect(
64-
batchRequests(mockServer.url, [{ document: `{ me { id } }` }, { document: `x` }])
64+
batchRequests(mockServer.url, [{ document: `{ me { id } }` }, { document: `x` }]),
6565
).rejects.toMatchInlineSnapshot(
66-
`[Error: GraphQL Error (Code: 200): {"response":{"0":{"data":{"me":{"id":"some-id"}}},"1":{"errors":{"message":"Syntax Error GraphQL request (1:1) Unexpected Name \\"x\\"\\n\\n1: x\\n ^\\n","locations":[{"line":1,"column":1}]}},"status":200,"headers":{}},"request":{"query":["{ me { id } }","x"],"variables":[null,null]}}]`
66+
`[Error: GraphQL Error (Code: 200): {"response":{"0":{"data":{"me":{"id":"some-id"}}},"1":{"errors":{"message":"Syntax Error GraphQL request (1:1) Unexpected Name \\"x\\"\\n\\n1: x\\n ^\\n","locations":[{"line":1,"column":1}]}},"status":200,"headers":{}},"request":{"query":["{ me { id } }","x"],"variables":[null,null]}}]`,
6767
)
6868
})
6969

tests/document-node.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ it(`accepts graphql DocumentNode as alternative to raw string`, async () => {
1515
users
1616
}
1717
}
18-
`
18+
`,
1919
)
2020
expect(mock).toMatchSnapshot()
2121
})

tests/general.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ test(`basic error`, async () => {
139139
const res = await request(ctx.url, `x`).catch((x) => x)
140140

141141
expect(res).toMatchInlineSnapshot(
142-
`[Error: GraphQL Error (Code: 200): {"response":{"errors":{"message":"Syntax Error GraphQL request (1:1) Unexpected Name \\"x\\"\\n\\n1: x\\n ^\\n","locations":[{"line":1,"column":1}]},"status":200,"headers":{}},"request":{"query":"x"}}]`
142+
`[Error: GraphQL Error (Code: 200): {"response":{"errors":{"message":"Syntax Error GraphQL request (1:1) Unexpected Name \\"x\\"\\n\\n1: x\\n ^\\n","locations":[{"line":1,"column":1}]},"status":200,"headers":{}},"request":{"query":"x"}}]`,
143143
)
144144
})
145145

@@ -159,7 +159,7 @@ test(`basic error with raw request`, async () => {
159159
})
160160
const res: unknown = await rawRequest(ctx.url, `x`).catch((x) => x)
161161
expect(res).toMatchInlineSnapshot(
162-
`[Error: GraphQL Error (Code: 200): {"response":{"errors":{"message":"Syntax Error GraphQL request (1:1) Unexpected Name \\"x\\"\\n\\n1: x\\n ^\\n","locations":[{"line":1,"column":1}]},"status":200,"headers":{}},"request":{"query":"x"}}]`
162+
`[Error: GraphQL Error (Code: 200): {"response":{"errors":{"message":"Syntax Error GraphQL request (1:1) Unexpected Name \\"x\\"\\n\\n1: x\\n ^\\n","locations":[{"line":1,"column":1}]},"status":200,"headers":{}},"request":{"query":"x"}}]`,
163163
)
164164
})
165165

@@ -370,7 +370,7 @@ describe(`operationName parsing`, () => {
370370
query myGqlOperation {
371371
users
372372
}
373-
`
373+
`,
374374
)
375375

376376
const requestBody = mock.requests[0]?.body
@@ -385,7 +385,7 @@ describe(`operationName parsing`, () => {
385385
query myStringOperation {
386386
users
387387
}
388-
`
388+
`,
389389
)
390390

391391
const requestBody = mock.requests[0]?.body

0 commit comments

Comments
 (0)