Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: layers revamp #1117

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Command } from '@molt/command'
import * as Path from 'node:path'
import { z } from 'zod'
import { generateFiles } from '../layers/2_generator/files.js'
import { generateFiles } from '../layers/4_generator/files.js'
import { urlParseSafe } from '../lib/prelude.js'

const args = Command.create().description(`Generate a type safe GraphQL client.`)
Expand Down
2 changes: 1 addition & 1 deletion src/entrypoints/generator.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { generateFiles as generate } from '../layers/2_generator/files.js'
export { generateFiles as generate } from '../layers/4_generator/files.js'
2 changes: 1 addition & 1 deletion src/entrypoints/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { execute } from '../layers/0_functions/execute.js'
export { gql } from '../layers/0_functions/gql.js'
export { type TypedDocumentString } from '../layers/0_functions/types.js'
export { createExtension, type Extension } from '../layers/6_client/extension.js'
export { gql } from '../layers/6_helpers/gql.js'
// todo figure this export out. Was just put there to resolve a type error about "...cannot be named..."
export * from '../layers/6_client/Settings/Input.js'
// todo figure this export out. Was just put there to resolve a type error about "...cannot be named..."
Expand Down
4 changes: 2 additions & 2 deletions src/entrypoints/schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from '../layers/1_Schema/__.js'
export { SelectionSet } from '../layers/3_SelectionSet/__.js'
export { ResultSet } from '../layers/4_ResultSet/__.js'
export { SelectionSet } from '../layers/2_SelectionSet/__.js'
export { ResultSet } from '../layers/3_ResultSet/__.js'
2 changes: 1 addition & 1 deletion src/entrypoints/utilities-for-generated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { type Simplify } from 'type-fest'
export * from '../layers/3_SelectionSet/__.js'
export * from '../layers/2_SelectionSet/__.js'
export { type DocumentRunner } from '../layers/6_client/document.js'
export type {
ConfigGetOutputError,
Expand Down
2 changes: 1 addition & 1 deletion src/layers/0_functions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type GetVariablesInputFromDocumentNode<$Document extends TypedQueryDocumentNode>
: { variables?: VariablesOf<$Document> }
: {}

export type HasVariables<$Document extends TypedQueryDocumentNode | TypedDocumentString> = Negate<
type HasVariables<$Document extends TypedQueryDocumentNode | TypedDocumentString> = Negate<
IsEmptyObject<VariablesOf<$Document>>
>

Expand Down
2 changes: 1 addition & 1 deletion src/layers/1_Schema/Hybrid/types/Scalar/Scalar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GlobalRegistry } from '../../../../2_generator/globalRegistry.js'
import type { GlobalRegistry } from '../../../../4_generator/globalRegistry.js'
import type { Codec } from './codec.js'
import { JavaScriptScalarCodecs } from './nativeScalarCodecs.js'

Expand Down
2 changes: 1 addition & 1 deletion src/layers/1_Schema/core/Index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RootTypeName } from '../../../lib/graphql.js'
import type { GlobalRegistry } from '../../2_generator/globalRegistry.js'
import type { GlobalRegistry } from '../../4_generator/globalRegistry.js'
import type { Hybrid } from '../Hybrid/__.js'
import type { Output } from '../Output/__.js'

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { assertArray, mapValues } from '../../lib/prelude.js'
import type { Object$2, Schema } from '../1_Schema/__.js'
import { Output } from '../1_Schema/__.js'
import { readMaybeThunk } from '../1_Schema/core/helpers.js'
import type { GraphQLObject } from '../4_ResultSet/runtime.js'
import { assertGraphQLObject } from '../4_ResultSet/runtime.js'
import type { GraphQLObject } from '../3_ResultSet/runtime.js'
import { assertGraphQLObject } from '../3_ResultSet/runtime.js'

export const decode = <$Data extends ExecutionResult['data']>(index: Schema.Object$2, data: $Data): $Data => {
if (!data) return data
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { ExcludeNull, GetKeyOr, mergeObjectArray, ValuesOrEmptyObject } fro
import type { TSError } from '../../lib/TSError.js'
import type { Schema, SomeField } from '../1_Schema/__.js'
import type { PickScalarFields } from '../1_Schema/Output/Output.js'
import type { SelectionSet } from '../3_SelectionSet/__.js'
import type { PickPositiveNonAliasIndicators } from '../3_SelectionSet/types.js'
import type { SelectionSet } from '../2_SelectionSet/__.js'
import type { PickPositiveNonAliasIndicators } from '../2_SelectionSet/types.js'

export type RootViaObject<
$SelectionSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
StandardScalarTypeTypeScriptMapping,
} from '../../../lib/graphql.js'
import type { StandardScalarTypeNames } from '../../../lib/graphql.js'
import { SelectionSet } from '../../3_SelectionSet/__.js'
import { SelectionSet } from '../../2_SelectionSet/__.js'
import { createCodeGenerator, createModuleGenerator } from '../createCodeGenerator.js'
import {
getDocumentation,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/layers/5_core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { mergeRequestInit, searchParamsAppendAll } from '../../lib/http.js'
import { casesExhausted, throwNull } from '../../lib/prelude.js'
import { execute } from '../0_functions/execute.js'
import type { Schema } from '../1_Schema/__.js'
import { SelectionSet } from '../3_SelectionSet/__.js'
import type { GraphQLObjectSelection } from '../3_SelectionSet/print.js'
import * as Result from '../4_ResultSet/customScalars.js'
import { SelectionSet } from '../2_SelectionSet/__.js'
import type { GraphQLObjectSelection } from '../2_SelectionSet/print.js'
import * as Result from '../3_ResultSet/customScalars.js'
import type { GraffleExecutionResultVar } from '../6_client/client.js'
import type { Config } from '../6_client/Settings/Config.js'
import {
Expand Down
2 changes: 1 addition & 1 deletion src/layers/5_select/select.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { identityProxy } from '../../lib/prelude.js'
import type { GlobalRegistry } from '../2_generator/globalRegistry.js'
import type { GlobalRegistry } from '../4_generator/globalRegistry.js'

// dprint-ignore
type Create = <$Name extends GlobalRegistry.SchemaNames>(name: $Name) =>
Expand Down
4 changes: 2 additions & 2 deletions src/layers/6_client/Settings/Config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RequireProperties, StringKeyof } from '../../../lib/prelude.js'
import type { Schema } from '../../1_Schema/__.js'
import type { GlobalRegistry } from '../../2_generator/globalRegistry.js'
import type { AliasInput } from '../../3_SelectionSet/types.js'
import type { AliasInput } from '../../2_SelectionSet/types.js'
import type { GlobalRegistry } from '../../4_generator/globalRegistry.js'
import type { Transport } from '../../5_core/types.js'
import type { ConfigGetOutputError } from '../handleOutput.js'
import type { TransportHttpInput } from '../transportHttp/request.js'
Expand Down
2 changes: 1 addition & 1 deletion src/layers/6_client/Settings/Input.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { GraphQLSchema } from 'graphql'
import type { Schema } from '../../1_Schema/__.js'
import type { GlobalRegistry } from '../../2_generator/globalRegistry.js'
import type { GlobalRegistry } from '../../4_generator/globalRegistry.js'
import type { WithInput } from './inputIncrementable/inputIncrementable.js'

export type URLInput = URL | string
Expand Down
2 changes: 1 addition & 1 deletion src/layers/6_client/Settings/InputToConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IsUnknown } from 'type-fest'
import type { ConfigManager } from '../../../lib/prelude.js'
import type { GlobalRegistry } from '../../2_generator/globalRegistry.js'
import type { GlobalRegistry } from '../../4_generator/globalRegistry.js'
import { Transport, type TransportHttp, type TransportMemory } from '../../5_core/types.js'
import { defaultMethodMode } from '../transportHttp/request.js'
import { type Config, outputConfigDefault } from './Config.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GlobalRegistry } from '../../../2_generator/globalRegistry.js'
import type { GlobalRegistry } from '../../../4_generator/globalRegistry.js'
import type { Transport, TransportMemory } from '../../../5_core/types.js'
import type { TransportHttpInput } from '../../transportHttp/request.js'
import type { Config } from '../Config.js'
Expand Down
2 changes: 1 addition & 1 deletion src/layers/6_client/Settings/inputIncrementable/output.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GlobalRegistry } from '../../../2_generator/globalRegistry.js'
import type { GlobalRegistry } from '../../../4_generator/globalRegistry.js'
import type { OutputChannel, OutputChannelConfig } from '../Config.js'
import type { InputOutputEnvelopeLonghand } from '../Input.js'
import type { IncrementableInputContext } from './inputIncrementable.js'
Expand Down
2 changes: 1 addition & 1 deletion src/layers/6_client/client.raw.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expectTypeOf } from 'vitest'
import { test } from '../../../tests/_/helpers.js'
import { Graffle } from '../../../tests/_/schema/generated/__.js'
import { schema } from '../../../tests/_/schema/schema.js'
import { gql } from '../0_functions/gql.js'
import { gql } from '../6_helpers/gql.js'
import type { RawResolveOutputReturnRootType } from './handleOutput.js'

const g = Graffle.create({ schema })
Expand Down
4 changes: 2 additions & 2 deletions src/layers/6_client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { proxyGet, type SimplifyExceptError } from '../../lib/prelude.js'
import type { BaseInput, BaseInput_, TypedDocumentString } from '../0_functions/types.js'
import { Schema } from '../1_Schema/__.js'
import { readMaybeThunk } from '../1_Schema/core/helpers.js'
import type { GlobalRegistry } from '../2_generator/globalRegistry.js'
import type { DocumentObject, GraphQLObjectSelection } from '../3_SelectionSet/print.js'
import type { DocumentObject, GraphQLObjectSelection } from '../2_SelectionSet/print.js'
import type { GlobalRegistry } from '../4_generator/globalRegistry.js'
import { Core } from '../5_core/__.js'
import { type HookDefEncode } from '../5_core/core.js'
import { type InterfaceRaw, type TransportHttp } from '../5_core/types.js'
Expand Down
6 changes: 3 additions & 3 deletions src/layers/6_client/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
} from '../../lib/graphql.js'
import type { FirstNonUnknownNever, IsKeyInObjectOptional, IsTupleMultiple, Values } from '../../lib/prelude.js'
import type { Schema } from '../1_Schema/__.js'
import { SelectionSet } from '../3_SelectionSet/__.js'
import type { Context, DocumentObject } from '../3_SelectionSet/print.js'
import type { ResultSet } from '../4_ResultSet/__.js'
import { SelectionSet } from '../2_SelectionSet/__.js'
import type { Context, DocumentObject } from '../2_SelectionSet/print.js'
import type { ResultSet } from '../3_ResultSet/__.js'
import type { ResolveOutputReturnRootType } from './handleOutput.js'
import type { AddTypenameToSelectedRootTypeResultFields, Config } from './Settings/Config.js'

Expand Down
2 changes: 1 addition & 1 deletion src/layers/6_client/prefilled.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { HasRequiredKeys } from 'type-fest'
import type { Exact } from '../../lib/prelude.js'
import type { Schema } from '../1_Schema/__.js'
import type { GlobalRegistry } from '../2_generator/globalRegistry.js'
import type { GlobalRegistry } from '../4_generator/globalRegistry.js'
import { type Client, create } from './client.js'
import type { InputBase } from './Settings/Input.js'
import type { InputToConfig } from './Settings/InputToConfig.js'
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/_/schemaGenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { GraphQLSchema } from 'graphql'
import { printSchema } from 'graphql'
import fs from 'node:fs/promises'
import { dirname, join } from 'node:path'
import { generateFiles } from '../../src/layers/2_generator/files.js'
import type { OptionsInput } from '../../src/layers/2_generator/generateCode.js'
import { generateFiles } from '../../src/layers/4_generator/files.js'
import type { OptionsInput } from '../../src/layers/4_generator/generateCode.js'
import { schema as schema } from './schema/schema.js'
import { schema as schemaMutationOnly } from './schemaMutationOnly/schema.js'
import { schema as schemaQueryOnly } from './schemaQueryOnly/schema.js'
Expand Down