From 8efd3b2a514ff8ac70443217ba4716bebeb4ba4d Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Thu, 4 Jul 2024 22:50:04 -0400 Subject: [PATCH] refactor: move client layer above core (#967) --- src/entrypoints/alpha/_Graffle.ts | 2 +- src/entrypoints/alpha/client.ts | 2 +- src/layers/0_functions/types.ts | 2 +- src/layers/3_SelectionSet/encode.ts | 2 +- src/layers/5_core/types.ts | 2 +- src/layers/5_createExtension/createExtension.ts | 2 +- src/layers/{5_client => 6_client}/Config.ts | 0 src/layers/{5_client => 6_client}/RootTypeMethods.ts | 0 src/layers/{5_client => 6_client}/client.batch.test.ts | 0 .../{5_client => 6_client}/client.customScalar.test.ts | 0 src/layers/{5_client => 6_client}/client.document.test-d.ts | 0 src/layers/{5_client => 6_client}/client.document.test.ts | 0 src/layers/{5_client => 6_client}/client.error.test-d.ts | 0 src/layers/{5_client => 6_client}/client.extend.test.ts | 5 ++++- src/layers/{5_client => 6_client}/client.input.test-d.ts | 0 src/layers/{5_client => 6_client}/client.raw.test.ts | 0 .../{5_client => 6_client}/client.returnMode.test-d.ts | 0 src/layers/{5_client => 6_client}/client.returnMode.test.ts | 0 .../{5_client => 6_client}/client.rootTypeMethods.test-d.ts | 0 .../{5_client => 6_client}/client.rootTypeMethods.test.ts | 0 src/layers/{5_client => 6_client}/client.test.ts | 0 src/layers/{5_client => 6_client}/client.ts | 0 src/layers/{5_client => 6_client}/document.ts | 0 src/layers/{5_client => 6_client}/types.ts | 0 .../{6_extensions => 7_extensions}/Upload/Upload.test.ts | 2 +- src/layers/{6_extensions => 7_extensions}/Upload/Upload.ts | 0 .../{6_extensions => 7_extensions}/Upload/extractFiles.ts | 0 tests/_/helpers.ts | 2 +- 28 files changed, 12 insertions(+), 9 deletions(-) rename src/layers/{5_client => 6_client}/Config.ts (100%) rename src/layers/{5_client => 6_client}/RootTypeMethods.ts (100%) rename src/layers/{5_client => 6_client}/client.batch.test.ts (100%) rename src/layers/{5_client => 6_client}/client.customScalar.test.ts (100%) rename src/layers/{5_client => 6_client}/client.document.test-d.ts (100%) rename src/layers/{5_client => 6_client}/client.document.test.ts (100%) rename src/layers/{5_client => 6_client}/client.error.test-d.ts (100%) rename src/layers/{5_client => 6_client}/client.extend.test.ts (92%) rename src/layers/{5_client => 6_client}/client.input.test-d.ts (100%) rename src/layers/{5_client => 6_client}/client.raw.test.ts (100%) rename src/layers/{5_client => 6_client}/client.returnMode.test-d.ts (100%) rename src/layers/{5_client => 6_client}/client.returnMode.test.ts (100%) rename src/layers/{5_client => 6_client}/client.rootTypeMethods.test-d.ts (100%) rename src/layers/{5_client => 6_client}/client.rootTypeMethods.test.ts (100%) rename src/layers/{5_client => 6_client}/client.test.ts (100%) rename src/layers/{5_client => 6_client}/client.ts (100%) rename src/layers/{5_client => 6_client}/document.ts (100%) rename src/layers/{5_client => 6_client}/types.ts (100%) rename src/layers/{6_extensions => 7_extensions}/Upload/Upload.test.ts (97%) rename src/layers/{6_extensions => 7_extensions}/Upload/Upload.ts (100%) rename src/layers/{6_extensions => 7_extensions}/Upload/extractFiles.ts (100%) diff --git a/src/entrypoints/alpha/_Graffle.ts b/src/entrypoints/alpha/_Graffle.ts index e140fdb5a..e832f9b39 100644 --- a/src/entrypoints/alpha/_Graffle.ts +++ b/src/entrypoints/alpha/_Graffle.ts @@ -1,2 +1,2 @@ -export * from '../../layers/5_client/client.js' +export * from '../../layers/6_client/client.js' export * as Scalars from './scalars.js' diff --git a/src/entrypoints/alpha/client.ts b/src/entrypoints/alpha/client.ts index ef621dca3..915dc00cf 100644 --- a/src/entrypoints/alpha/client.ts +++ b/src/entrypoints/alpha/client.ts @@ -1,2 +1,2 @@ -export { Client, create, createPrefilled, Input, InputPrefilled } from '../../layers/5_client/client.js' export { create as createSelect, select } from '../../layers/5_select/select.js' +export { Client, create, createPrefilled, Input, InputPrefilled } from '../../layers/6_client/client.js' diff --git a/src/layers/0_functions/types.ts b/src/layers/0_functions/types.ts index e18503eea..abf4edcea 100644 --- a/src/layers/0_functions/types.ts +++ b/src/layers/0_functions/types.ts @@ -1,5 +1,5 @@ import type { StandardScalarVariables } from '../../lib/graphql.js' -import type { DocumentInput, OperationNameInput } from '../5_client/types.js' +import type { DocumentInput, OperationNameInput } from '../6_client/types.js' export interface BaseInput { document: DocumentInput diff --git a/src/layers/3_SelectionSet/encode.ts b/src/layers/3_SelectionSet/encode.ts index f29da32c7..9455d42a8 100644 --- a/src/layers/3_SelectionSet/encode.ts +++ b/src/layers/3_SelectionSet/encode.ts @@ -2,7 +2,7 @@ import { RootTypeName } from '../../lib/graphql.js' import { assertArray, assertObject, lowerCaseFirstLetter } from '../../lib/prelude.js' import { Schema } from '../1_Schema/__.js' import { readMaybeThunk } from '../1_Schema/core/helpers.js' -import type { ReturnModeType } from '../5_client/Config.js' +import type { ReturnModeType } from '../6_client/Config.js' import type { SelectionSet } from './__.js' import { isSelectFieldName } from './helpers.js' import { parseClientDirectiveDefer } from './runtime/directives/defer.js' diff --git a/src/layers/5_core/types.ts b/src/layers/5_core/types.ts index 611279959..22f360ad5 100644 --- a/src/layers/5_core/types.ts +++ b/src/layers/5_core/types.ts @@ -1,5 +1,5 @@ import type { Schema } from '../1_Schema/__.js' -import type { Config } from '../5_client/Config.js' +import type { Config } from '../6_client/Config.js' export type Transport = TransportMemory | TransportHttp diff --git a/src/layers/5_createExtension/createExtension.ts b/src/layers/5_createExtension/createExtension.ts index 0c742381b..d2a5a7edb 100644 --- a/src/layers/5_createExtension/createExtension.ts +++ b/src/layers/5_createExtension/createExtension.ts @@ -1,3 +1,3 @@ -import type { Extension } from '../5_client/client.js' +import type { Extension } from '../6_client/client.js' export const createExtension = (input: Extension) => input diff --git a/src/layers/5_client/Config.ts b/src/layers/6_client/Config.ts similarity index 100% rename from src/layers/5_client/Config.ts rename to src/layers/6_client/Config.ts diff --git a/src/layers/5_client/RootTypeMethods.ts b/src/layers/6_client/RootTypeMethods.ts similarity index 100% rename from src/layers/5_client/RootTypeMethods.ts rename to src/layers/6_client/RootTypeMethods.ts diff --git a/src/layers/5_client/client.batch.test.ts b/src/layers/6_client/client.batch.test.ts similarity index 100% rename from src/layers/5_client/client.batch.test.ts rename to src/layers/6_client/client.batch.test.ts diff --git a/src/layers/5_client/client.customScalar.test.ts b/src/layers/6_client/client.customScalar.test.ts similarity index 100% rename from src/layers/5_client/client.customScalar.test.ts rename to src/layers/6_client/client.customScalar.test.ts diff --git a/src/layers/5_client/client.document.test-d.ts b/src/layers/6_client/client.document.test-d.ts similarity index 100% rename from src/layers/5_client/client.document.test-d.ts rename to src/layers/6_client/client.document.test-d.ts diff --git a/src/layers/5_client/client.document.test.ts b/src/layers/6_client/client.document.test.ts similarity index 100% rename from src/layers/5_client/client.document.test.ts rename to src/layers/6_client/client.document.test.ts diff --git a/src/layers/5_client/client.error.test-d.ts b/src/layers/6_client/client.error.test-d.ts similarity index 100% rename from src/layers/5_client/client.error.test-d.ts rename to src/layers/6_client/client.error.test-d.ts diff --git a/src/layers/5_client/client.extend.test.ts b/src/layers/6_client/client.extend.test.ts similarity index 92% rename from src/layers/5_client/client.extend.test.ts rename to src/layers/6_client/client.extend.test.ts index edccd2213..b042de072 100644 --- a/src/layers/5_client/client.extend.test.ts +++ b/src/layers/6_client/client.extend.test.ts @@ -8,7 +8,10 @@ import { oops } from '../../lib/anyware/specHelpers.js' const client = Graffle.create({ schema: 'https://foo', returnMode: 'dataAndErrors' }) const headers = { 'x-foo': 'bar' } -// todo each extension added should copy, not mutate the client +test('using an extension returns a copy of the client', () => { + const client2 = client.use(async () => {}) + expect(client2 !== client).toBe(true) +}) describe(`entrypoint pack`, () => { test(`can add header`, async ({ fetch }) => { diff --git a/src/layers/5_client/client.input.test-d.ts b/src/layers/6_client/client.input.test-d.ts similarity index 100% rename from src/layers/5_client/client.input.test-d.ts rename to src/layers/6_client/client.input.test-d.ts diff --git a/src/layers/5_client/client.raw.test.ts b/src/layers/6_client/client.raw.test.ts similarity index 100% rename from src/layers/5_client/client.raw.test.ts rename to src/layers/6_client/client.raw.test.ts diff --git a/src/layers/5_client/client.returnMode.test-d.ts b/src/layers/6_client/client.returnMode.test-d.ts similarity index 100% rename from src/layers/5_client/client.returnMode.test-d.ts rename to src/layers/6_client/client.returnMode.test-d.ts diff --git a/src/layers/5_client/client.returnMode.test.ts b/src/layers/6_client/client.returnMode.test.ts similarity index 100% rename from src/layers/5_client/client.returnMode.test.ts rename to src/layers/6_client/client.returnMode.test.ts diff --git a/src/layers/5_client/client.rootTypeMethods.test-d.ts b/src/layers/6_client/client.rootTypeMethods.test-d.ts similarity index 100% rename from src/layers/5_client/client.rootTypeMethods.test-d.ts rename to src/layers/6_client/client.rootTypeMethods.test-d.ts diff --git a/src/layers/5_client/client.rootTypeMethods.test.ts b/src/layers/6_client/client.rootTypeMethods.test.ts similarity index 100% rename from src/layers/5_client/client.rootTypeMethods.test.ts rename to src/layers/6_client/client.rootTypeMethods.test.ts diff --git a/src/layers/5_client/client.test.ts b/src/layers/6_client/client.test.ts similarity index 100% rename from src/layers/5_client/client.test.ts rename to src/layers/6_client/client.test.ts diff --git a/src/layers/5_client/client.ts b/src/layers/6_client/client.ts similarity index 100% rename from src/layers/5_client/client.ts rename to src/layers/6_client/client.ts diff --git a/src/layers/5_client/document.ts b/src/layers/6_client/document.ts similarity index 100% rename from src/layers/5_client/document.ts rename to src/layers/6_client/document.ts diff --git a/src/layers/5_client/types.ts b/src/layers/6_client/types.ts similarity index 100% rename from src/layers/5_client/types.ts rename to src/layers/6_client/types.ts diff --git a/src/layers/6_extensions/Upload/Upload.test.ts b/src/layers/7_extensions/Upload/Upload.test.ts similarity index 97% rename from src/layers/6_extensions/Upload/Upload.test.ts rename to src/layers/7_extensions/Upload/Upload.test.ts index 2c4ee4fa5..cbae3c1cf 100644 --- a/src/layers/6_extensions/Upload/Upload.test.ts +++ b/src/layers/7_extensions/Upload/Upload.test.ts @@ -10,7 +10,7 @@ import { Graffle } from '../../../entrypoints/alpha/main.js' import { Upload } from './Upload.js' import { createYoga } from 'graphql-yoga' -import type { Client } from '../../5_client/client.js' +import type { Client } from '../../6_client/client.js' let server: Server let port: number diff --git a/src/layers/6_extensions/Upload/Upload.ts b/src/layers/7_extensions/Upload/Upload.ts similarity index 100% rename from src/layers/6_extensions/Upload/Upload.ts rename to src/layers/7_extensions/Upload/Upload.ts diff --git a/src/layers/6_extensions/Upload/extractFiles.ts b/src/layers/7_extensions/Upload/extractFiles.ts similarity index 100% rename from src/layers/6_extensions/Upload/extractFiles.ts rename to src/layers/7_extensions/Upload/extractFiles.ts diff --git a/tests/_/helpers.ts b/tests/_/helpers.ts index e667577d3..e87e5d138 100644 --- a/tests/_/helpers.ts +++ b/tests/_/helpers.ts @@ -11,7 +11,7 @@ interface Fixtures { } import { Graffle } from '../../src/entrypoints/alpha/main.js' -import type { Client } from '../../src/layers/5_client/client.js' +import type { Client } from '../../src/layers/6_client/client.js' export const test = testBase.extend({ // @ts-expect-error https://github.com/vitest-dev/vitest/discussions/5710