From 4d4ac4cc201e03aa70ab5182205b04bff6d4271d Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Mon, 12 Feb 2024 18:43:34 -0500 Subject: [PATCH] refactor: move existing api to legacy dir (#670) --- examples/other-middleware.ts | 2 +- src/entrypoints/main.ts | 24 +++++++++---------- src/{ => legacy}/classes/ClientError.ts | 0 src/{ => legacy}/classes/GraphQLClient.ts | 2 +- src/{ => legacy}/functions/batchRequests.ts | 0 src/{ => legacy}/functions/gql.ts | 0 src/{ => legacy}/functions/rawRequest.ts | 0 src/{ => legacy}/functions/request.ts | 0 src/{ => legacy}/helpers/analyzeDocument.ts | 2 +- .../helpers/defaultJsonSerializer.ts | 0 src/{ => legacy}/helpers/runRequest.ts | 4 ++-- src/{ => legacy}/helpers/types.ts | 2 +- src/{ => legacy}/lib/graphql-ws.ts | 0 src/{ => legacy}/lib/graphql.ts | 4 ++-- tests/httpMethod.test.ts | 2 +- tests/json-serializer.test.ts | 2 +- 16 files changed, 22 insertions(+), 22 deletions(-) rename src/{ => legacy}/classes/ClientError.ts (100%) rename src/{ => legacy}/classes/GraphQLClient.ts (98%) rename src/{ => legacy}/functions/batchRequests.ts (100%) rename src/{ => legacy}/functions/gql.ts (100%) rename src/{ => legacy}/functions/rawRequest.ts (100%) rename src/{ => legacy}/functions/request.ts (100%) rename src/{ => legacy}/helpers/analyzeDocument.ts (97%) rename src/{ => legacy}/helpers/defaultJsonSerializer.ts (100%) rename src/{ => legacy}/helpers/runRequest.ts (98%) rename src/{ => legacy}/helpers/types.ts (98%) rename src/{ => legacy}/lib/graphql-ws.ts (100%) rename src/{ => legacy}/lib/graphql.ts (96%) diff --git a/examples/other-middleware.ts b/examples/other-middleware.ts index 4cfbcbadd..7686d03a9 100644 --- a/examples/other-middleware.ts +++ b/examples/other-middleware.ts @@ -2,8 +2,8 @@ * It's possible to use a middleware to pre-process any request or handle raw response. */ +import type { RequestMiddleware, ResponseMiddleware } from '../src/entrypoints/main.js' import { GraphQLClient } from '../src/entrypoints/main.js' -import type { RequestMiddleware, ResponseMiddleware } from '../src/helpers/types.js' const endpoint = `https://api.spacex.land/graphql/` diff --git a/src/entrypoints/main.ts b/src/entrypoints/main.ts index 262c81c8f..41c97b43f 100644 --- a/src/entrypoints/main.ts +++ b/src/entrypoints/main.ts @@ -1,19 +1,19 @@ -import { ClientError } from '../classes/ClientError.js' +import { ClientError } from '../legacy/classes/ClientError.js' import { type BatchRequestDocument, type BatchRequestsExtendedOptions, type BatchRequestsOptions, -} from '../functions/batchRequests.js' -import { RequestExtendedOptions } from '../functions/request.js' -import { request } from '../functions/request.js' -import type { GraphQLResponse, RequestMiddleware, ResponseMiddleware } from '../helpers/types.js' -import { RawRequestOptions, RequestDocument, RequestOptions, Variables } from '../helpers/types.js' -export { GraphQLClient } from '../classes/GraphQLClient.js' -export { batchRequests } from '../functions/batchRequests.js' -export { gql } from '../functions/gql.js' -export { rawRequest } from '../functions/rawRequest.js' -export { analyzeDocument } from '../helpers/analyzeDocument.js' -export { GraphQLWebSocketClient } from '../lib/graphql-ws.js' +} from '../legacy/functions/batchRequests.js' +import { RequestExtendedOptions } from '../legacy/functions/request.js' +import { request } from '../legacy/functions/request.js' +import type { GraphQLResponse, RequestMiddleware, ResponseMiddleware } from '../legacy/helpers/types.js' +import { RawRequestOptions, RequestDocument, RequestOptions, Variables } from '../legacy/helpers/types.js' +export { GraphQLClient } from '../legacy/classes/GraphQLClient.js' +export { batchRequests } from '../legacy/functions/batchRequests.js' +export { gql } from '../legacy/functions/gql.js' +export { rawRequest } from '../legacy/functions/rawRequest.js' +export { analyzeDocument } from '../legacy/helpers/analyzeDocument.js' +export { GraphQLWebSocketClient } from '../legacy/lib/graphql-ws.js' export { BatchRequestDocument, BatchRequestsExtendedOptions, diff --git a/src/classes/ClientError.ts b/src/legacy/classes/ClientError.ts similarity index 100% rename from src/classes/ClientError.ts rename to src/legacy/classes/ClientError.ts diff --git a/src/classes/GraphQLClient.ts b/src/legacy/classes/GraphQLClient.ts similarity index 98% rename from src/classes/GraphQLClient.ts rename to src/legacy/classes/GraphQLClient.ts index eae6e8094..112dfff6d 100644 --- a/src/classes/GraphQLClient.ts +++ b/src/legacy/classes/GraphQLClient.ts @@ -1,3 +1,4 @@ +import { callOrIdentity, HeadersInitToPlainObject } from '../../lib/prelude.js' import type { BatchRequestDocument, BatchRequestsOptions, BatchResult } from '../functions/batchRequests.js' import { parseBatchRequestArgs } from '../functions/batchRequests.js' import { parseRawRequestArgs } from '../functions/rawRequest.js' @@ -11,7 +12,6 @@ import { type RequestConfig, type Variables, } from '../helpers/types.js' -import { callOrIdentity, HeadersInitToPlainObject } from '../lib/prelude.js' import type { TypedDocumentNode } from '@graphql-typed-document-node/core' /** diff --git a/src/functions/batchRequests.ts b/src/legacy/functions/batchRequests.ts similarity index 100% rename from src/functions/batchRequests.ts rename to src/legacy/functions/batchRequests.ts diff --git a/src/functions/gql.ts b/src/legacy/functions/gql.ts similarity index 100% rename from src/functions/gql.ts rename to src/legacy/functions/gql.ts diff --git a/src/functions/rawRequest.ts b/src/legacy/functions/rawRequest.ts similarity index 100% rename from src/functions/rawRequest.ts rename to src/legacy/functions/rawRequest.ts diff --git a/src/functions/request.ts b/src/legacy/functions/request.ts similarity index 100% rename from src/functions/request.ts rename to src/legacy/functions/request.ts diff --git a/src/helpers/analyzeDocument.ts b/src/legacy/helpers/analyzeDocument.ts similarity index 97% rename from src/helpers/analyzeDocument.ts rename to src/legacy/helpers/analyzeDocument.ts index 0deeaeadc..21a515a77 100644 --- a/src/helpers/analyzeDocument.ts +++ b/src/legacy/helpers/analyzeDocument.ts @@ -1,5 +1,5 @@ +import { tryCatch } from '../../lib/prelude.js' import { isOperationDefinitionNode } from '../lib/graphql.js' -import { tryCatch } from '../lib/prelude.js' import type { RequestDocument } from './types.js' /** * Refactored imports from `graphql` to be more specific, this helps import only the required files (100KiB) diff --git a/src/helpers/defaultJsonSerializer.ts b/src/legacy/helpers/defaultJsonSerializer.ts similarity index 100% rename from src/helpers/defaultJsonSerializer.ts rename to src/legacy/helpers/defaultJsonSerializer.ts diff --git a/src/helpers/runRequest.ts b/src/legacy/helpers/runRequest.ts similarity index 98% rename from src/helpers/runRequest.ts rename to src/legacy/helpers/runRequest.ts index 4a2577a8e..8cdecdd42 100644 --- a/src/helpers/runRequest.ts +++ b/src/legacy/helpers/runRequest.ts @@ -1,3 +1,5 @@ +import { ACCEPT_HEADER, CONTENT_TYPE_GQL, CONTENT_TYPE_HEADER, CONTENT_TYPE_JSON } from '../../lib/http.js' +import { casesExhausted, uppercase, zip } from '../../lib/prelude.js' import { ClientError } from '../classes/ClientError.js' import type { GraphQLExecutionResultSingle } from '../lib/graphql.js' import { @@ -6,8 +8,6 @@ import { isRequestResultHaveErrors, parseGraphQLExecutionResult, } from '../lib/graphql.js' -import { ACCEPT_HEADER, CONTENT_TYPE_GQL, CONTENT_TYPE_HEADER, CONTENT_TYPE_JSON } from '../lib/http.js' -import { casesExhausted, uppercase, zip } from '../lib/prelude.js' import { defaultJsonSerializer } from './defaultJsonSerializer.js' import type { BatchVariables, diff --git a/src/helpers/types.ts b/src/legacy/helpers/types.ts similarity index 98% rename from src/helpers/types.ts rename to src/legacy/helpers/types.ts index 86efd81b6..2acd61c5d 100644 --- a/src/helpers/types.ts +++ b/src/legacy/helpers/types.ts @@ -1,5 +1,5 @@ +import type { MaybeLazy, RemoveIndex } from '../../lib/prelude.js' import type { ClientError } from '../classes/ClientError.js' -import type { MaybeLazy, RemoveIndex } from '../lib/prelude.js' import type { TypedDocumentNode } from '@graphql-typed-document-node/core' import type { GraphQLError } from 'graphql/error/GraphQLError.js' import type { DocumentNode } from 'graphql/language/ast.js' diff --git a/src/lib/graphql-ws.ts b/src/legacy/lib/graphql-ws.ts similarity index 100% rename from src/lib/graphql-ws.ts rename to src/legacy/lib/graphql-ws.ts diff --git a/src/lib/graphql.ts b/src/legacy/lib/graphql.ts similarity index 96% rename from src/lib/graphql.ts rename to src/legacy/lib/graphql.ts index ab3f8392e..7362c649e 100644 --- a/src/lib/graphql.ts +++ b/src/legacy/lib/graphql.ts @@ -1,5 +1,5 @@ -import { CONTENT_TYPE_GQL, CONTENT_TYPE_JSON } from './http.js' -import { isPlainObject } from './prelude.js' +import { CONTENT_TYPE_GQL, CONTENT_TYPE_JSON } from '../../lib/http.js' +import { isPlainObject } from '../../lib/prelude.js' import { Kind } from 'graphql' /** * Refactored imports from `graphql` to be more specific, this helps import only the required files (100KiB) diff --git a/tests/httpMethod.test.ts b/tests/httpMethod.test.ts index 8fe2d538d..da0af7366 100644 --- a/tests/httpMethod.test.ts +++ b/tests/httpMethod.test.ts @@ -1,5 +1,5 @@ import { gql, GraphQLClient } from '../src/entrypoints/main.js' -import type { RequestConfig } from '../src/helpers/types.js' +import type { RequestConfig } from '../src/legacy/helpers/types.js' import { CONTENT_TYPE_HEADER, statusCodes } from '../src/lib/http.js' import { expect, test, vitest } from 'vitest' diff --git a/tests/json-serializer.test.ts b/tests/json-serializer.test.ts index 3362ac17e..4b18d1876 100644 --- a/tests/json-serializer.test.ts +++ b/tests/json-serializer.test.ts @@ -1,5 +1,5 @@ import { GraphQLClient } from '../src/entrypoints/main.js' -import type { Fetch, Variables } from '../src/helpers/types.js' +import type { Fetch, Variables } from '../src/legacy/helpers/types.js' import { CONTENT_TYPE_HEADER, statusCodes } from '../src/lib/http.js' import { setupMockServer } from './__helpers.js' import { beforeEach, describe, expect, test, vitest } from 'vitest'