diff --git a/README.md b/README.md index 936cc3d4..38c62bfc 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ const document = gql` } } ` -const endpoint = 'https://api.spacex.land/graphql/'; +const endpoint = 'https://api.spacex.land/graphql/' const client = new GraphQLClient(endpoint) await client.request(document) ``` diff --git a/examples/configuration-request-json-serializer.ts b/examples/configuration-request-json-serializer.ts index 92de9a4c..7a3f4a91 100644 --- a/examples/configuration-request-json-serializer.ts +++ b/examples/configuration-request-json-serializer.ts @@ -8,11 +8,9 @@ import JSONbig from 'json-bigint' const jsonSerializer = JSONbig({ useNativeBigInt: true }) const graphQLClient = new GraphQLClient(`https://some-api`, { jsonSerializer }) -const data = await graphQLClient.request<{ someBigInt: bigint }>( - gql` - { - someBigInt - } - ` -) +const data = await graphQLClient.request<{ someBigInt: bigint }>(gql` + { + someBigInt + } +`) console.log(typeof data.someBigInt) // if >MAX_SAFE_INTEGER then 'bigint' else 'number' diff --git a/examples/other-middleware.ts b/examples/other-middleware.ts index 2fec87de..54876358 100644 --- a/examples/other-middleware.ts +++ b/examples/other-middleware.ts @@ -52,7 +52,7 @@ const getAccessToken = () => Promise.resolve(`some special token here`) console.error( `[${traceId}] Request error: status ${response.status} - details: ${response.errors.map((_) => _.message).join(`, `)}` + details: ${response.errors.map((_) => _.message).join(`, `)}`, ) } } diff --git a/src/index.ts b/src/index.ts index 7dfe6d89..7a213ee3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -110,7 +110,7 @@ const buildRequestConfig = (params: BuildRequestConfigParam }) return acc }, - [] + [], ) return `query=${encodeURIComponent(params_.jsonSerializer.stringify(payload))}` @@ -179,7 +179,10 @@ const createHttpMethodFetcher = * GraphQL Client. */ class GraphQLClient { - constructor(private url: string, public readonly requestConfig: RequestConfig = {}) {} + constructor( + private url: string, + public readonly requestConfig: RequestConfig = {}, + ) {} /** * Send a GraphQL query to the server. @@ -422,7 +425,7 @@ const makeRequest = async (params: throw new ClientError( // @ts-expect-error TODO { ...errorResult, status: response.status, headers: response.headers }, - { query, variables } + { query, variables }, ) } } @@ -586,7 +589,7 @@ const createRequestBody = ( query: string | string[], variables?: Variables | Variables[], operationName?: string, - jsonSerializer?: JsonSerializer + jsonSerializer?: JsonSerializer, ): string => { const jsonSerializer_ = jsonSerializer ?? defaultJsonSerializer if (!Array.isArray(query)) { @@ -603,7 +606,7 @@ const createRequestBody = ( acc.push({ query: currentQuery, variables: variables ? variables[index] : undefined }) return acc }, - [] + [], ) return jsonSerializer_.stringify(payload) @@ -611,7 +614,7 @@ const createRequestBody = ( const getResult = async ( response: Response, - jsonSerializer: JsonSerializer + jsonSerializer: JsonSerializer, ): Promise< | { data: object; errors: undefined }[] | { data: object; errors: undefined } @@ -659,7 +662,7 @@ const callOrIdentity = (value: MaybeLazy) => { export const gql = (chunks: TemplateStringsArray, ...variables: unknown[]): string => { return chunks.reduce( (acc, chunk, index) => `${acc}${chunk}${index in variables ? String(variables[index]) : ``}`, - `` + ``, ) } diff --git a/src/parseArgs.ts b/src/parseArgs.ts index ef7bb6ab..49a5a81e 100644 --- a/src/parseArgs.ts +++ b/src/parseArgs.ts @@ -14,7 +14,7 @@ import type { export const parseRequestArgs = ( documentOrOptions: RequestDocument | RequestOptions, variables?: V, - requestHeaders?: GraphQLClientRequestHeaders + requestHeaders?: GraphQLClientRequestHeaders, ): RequestOptions => { return (documentOrOptions as RequestOptions).document ? (documentOrOptions as RequestOptions) @@ -29,7 +29,7 @@ export const parseRequestArgs = ( export const parseRawRequestArgs = ( queryOrOptions: string | RawRequestOptions, variables?: V, - requestHeaders?: GraphQLClientRequestHeaders + requestHeaders?: GraphQLClientRequestHeaders, ): RawRequestOptions => { return (queryOrOptions as RawRequestOptions).query ? (queryOrOptions as RawRequestOptions) @@ -43,7 +43,7 @@ export const parseRawRequestArgs = ( export const parseBatchRequestArgs = ( documentsOrOptions: BatchRequestDocument[] | BatchRequestsOptions, - requestHeaders?: GraphQLClientRequestHeaders + requestHeaders?: GraphQLClientRequestHeaders, ): BatchRequestsOptions => { return (documentsOrOptions as BatchRequestsOptions).documents ? (documentsOrOptions as BatchRequestsOptions) diff --git a/src/resolveRequestDocument.ts b/src/resolveRequestDocument.ts index b7fd439c..6d73cc3a 100644 --- a/src/resolveRequestDocument.ts +++ b/src/resolveRequestDocument.ts @@ -1,6 +1,6 @@ import type { RequestDocument } from './types.js' /** - * Refactored imports from `graphql` to be more specific, this helps import only the required files (100KiB) + * Refactored imports from `graphql` to be more specific, this helps import only the required files (100KiB) * instead of the entire package (>500KiB) where tree-shaking is not supported. * @see https://github.com/jasonkuhrt/graphql-request/pull/543 */ @@ -16,7 +16,7 @@ const extractOperationName = (document: DocumentNode): string | undefined => { let operationName = undefined const operationDefinitions = document.definitions.filter( - (definition) => definition.kind === `OperationDefinition` + (definition) => definition.kind === `OperationDefinition`, ) as OperationDefinitionNode[] if (operationDefinitions.length === 1) { @@ -27,7 +27,7 @@ const extractOperationName = (document: DocumentNode): string | undefined => { } export const resolveRequestDocument = ( - document: RequestDocument + document: RequestDocument, ): { query: string; operationName?: string } => { if (typeof document === `string`) { let operationName = undefined diff --git a/tests/__helpers.ts b/tests/__helpers.ts index 56e26661..14064bf3 100644 --- a/tests/__helpers.ts +++ b/tests/__helpers.ts @@ -47,7 +47,7 @@ type MockResult = { } export const setupMockServer = ( - delay?: number + delay?: number, ): Context => { const ctx = {} as Context beforeAll(async () => { diff --git a/tests/batching.test.ts b/tests/batching.test.ts index b48286d0..e45d0a63 100644 --- a/tests/batching.test.ts +++ b/tests/batching.test.ts @@ -38,7 +38,7 @@ test(`basic error`, async () => { }) await expect(batchRequests(mockServer.url, [{ document: `x` }])).rejects.toMatchInlineSnapshot( - `[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]}}]` + `[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]}}]`, ) }) @@ -61,9 +61,9 @@ test(`successful query with another which make an error`, async () => { }) await expect( - batchRequests(mockServer.url, [{ document: `{ me { id } }` }, { document: `x` }]) + batchRequests(mockServer.url, [{ document: `{ me { id } }` }, { document: `x` }]), ).rejects.toMatchInlineSnapshot( - `[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]}}]` + `[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]}}]`, ) }) diff --git a/tests/document-node.test.ts b/tests/document-node.test.ts index 08fa375c..314c1548 100644 --- a/tests/document-node.test.ts +++ b/tests/document-node.test.ts @@ -15,7 +15,7 @@ it(`accepts graphql DocumentNode as alternative to raw string`, async () => { users } } - ` + `, ) expect(mock).toMatchSnapshot() }) diff --git a/tests/general.test.ts b/tests/general.test.ts index 3d05c8b5..a3520a95 100644 --- a/tests/general.test.ts +++ b/tests/general.test.ts @@ -139,7 +139,7 @@ test(`basic error`, async () => { const res = await request(ctx.url, `x`).catch((x) => x) expect(res).toMatchInlineSnapshot( - `[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"}}]` + `[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"}}]`, ) }) @@ -159,7 +159,7 @@ test(`basic error with raw request`, async () => { }) const res: unknown = await rawRequest(ctx.url, `x`).catch((x) => x) expect(res).toMatchInlineSnapshot( - `[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"}}]` + `[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"}}]`, ) }) @@ -370,7 +370,7 @@ describe(`operationName parsing`, () => { query myGqlOperation { users } - ` + `, ) const requestBody = mock.requests[0]?.body @@ -385,7 +385,7 @@ describe(`operationName parsing`, () => { query myStringOperation { users } - ` + `, ) const requestBody = mock.requests[0]?.body diff --git a/tests/gql.test.ts b/tests/gql.test.ts index 58b0b43c..193a57be 100644 --- a/tests/gql.test.ts +++ b/tests/gql.test.ts @@ -14,7 +14,7 @@ describe(`gql`, () => { query allUsers { users } - ` + `, ) expect(mock).toMatchSnapshot() }) diff --git a/tests/graphql-ws.test.ts b/tests/graphql-ws.test.ts index a8b10174..2d0bd4e3 100644 --- a/tests/graphql-ws.test.ts +++ b/tests/graphql-ws.test.ts @@ -57,13 +57,11 @@ afterAll(() => { test(`graphql-ws request`, async () => { const client = await createClient(ctx.url) - const data = client.request( - gql` - query hello { - hello - } - ` - ) + const data = client.request(gql` + query hello { + hello + } + `) expect(await data).toEqual({ hello: `world` }) client.close() }) @@ -84,7 +82,7 @@ test(`graphql-ws subscription`, async () => { complete: () => { resolve(allGreetings) }, - } + }, ) }) expect(await result).toEqual(`Hi,Bonjour,Hola,Ciao,Zdravo`)