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: organize dirs by layer #805

Merged
merged 2 commits into from
Apr 27, 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 '../generator/files.js'
import { generateFiles } from '../layers/2_generator/files.js'

const args = Command.create().description(`Generate a type safe GraphQL client.`)
.parameter(`schema`, z.string().min(1).describe(`File path to where your GraphQL schema is.`))
Expand Down
4 changes: 2 additions & 2 deletions src/entrypoints/alpha/client.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from '../../client/client.js'
export { create as createSelect, select } from '../../select.js'
export * from '../../layers/4_client/client.js'
export { create as createSelect, select } from '../../layers/4_select/select.js'
2 changes: 1 addition & 1 deletion src/entrypoints/alpha/scalars.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from '../../Schema/Hybrid/types/Scalar/Scalar.js'
export * from '../../layers/1_Schema/Hybrid/types/Scalar/Scalar.js'
6 changes: 3 additions & 3 deletions src/entrypoints/alpha/schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { ResultSet } from '../../client/ResultSet/__.js'
export { SelectionSet } from '../../client/SelectionSet/__.js'
export * from '../../Schema/__.js'
export * from '../../layers/1_Schema/__.js'
export { ResultSet } from '../../layers/3_IO/ResultSet/__.js'
export { SelectionSet } from '../../layers/3_IO/SelectionSet/__.js'
22 changes: 11 additions & 11 deletions src/entrypoints/main.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { ClientError } from '../raw/classes/ClientError.js'
import { ClientError } from '../legacy/classes/ClientError.js'
import {
type BatchRequestDocument,
type BatchRequestsExtendedOptions,
type BatchRequestsOptions,
} from '../raw/functions/batchRequests.js'
import type { RequestExtendedOptions } from '../raw/functions/request.js'
import { request } from '../raw/functions/request.js'
import type { GraphQLResponse, RequestMiddleware, ResponseMiddleware } from '../raw/helpers/types.js'
import type { RawRequestOptions, RequestDocument, RequestOptions, Variables } from '../raw/helpers/types.js'
export { GraphQLClient } from '../raw/classes/GraphQLClient.js'
export { batchRequests } from '../raw/functions/batchRequests.js'
export { gql } from '../raw/functions/gql.js'
export { rawRequest } from '../raw/functions/rawRequest.js'
export { analyzeDocument } from '../raw/helpers/analyzeDocument.js'
} from '../legacy/functions/batchRequests.js'
import type { RequestExtendedOptions } from '../legacy/functions/request.js'
import { request } from '../legacy/functions/request.js'
import type { GraphQLResponse, RequestMiddleware, ResponseMiddleware } from '../legacy/helpers/types.js'
import type { 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 {
BatchRequestDocument,
BatchRequestsExtendedOptions,
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.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TSError } from '../../lib/TSError.js'
import type { TSError } from '../../../lib/TSError.js'
import { readMaybeThunk } from '../core/helpers.js'
import type { Any, Named } from './typeGroups.js'
import type { __typename } from './types/__typename.js'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GlobalRegistry } from '../../globalRegistry.js'
import type { GlobalRegistry } from '../../2_generator/globalRegistry.js'
import type { Output } from '../Output/__.js'

export interface Index {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Digit, Letter } from '../../../lib/prelude.js'
import type { Digit, Letter } from '../../../../lib/prelude.js'

/**
* @see http://spec.graphql.org/draft/#sec-Names
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export namespace Union {
`;

exports[`schema2 5`] = `
"export * from '../../../../src/Schema/Hybrid/types/Scalar/Scalar.js'
"export * from '../../../../src/layers/1_Schema/Hybrid/types/Scalar/Scalar.js'
export * from '../../customScalarCodecs.js'
"
`;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isUnionType } from 'graphql'
import { Code } from '../../lib/Code.js'
import { hasMutation, hasQuery, hasSubscription, unwrapToNamed } from '../../lib/graphql.js'
import { Code } from '../../../lib/Code.js'
import { hasMutation, hasQuery, hasSubscription, unwrapToNamed } from '../../../lib/graphql.js'
import type { Config } from './generateCode.js'
import { moduleNameSchemaBuildtime } from './SchemaBuildtime.js'

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
} from 'graphql'
import { isEnumType, isListType, isNamedType } from 'graphql'
import _ from 'json-bigint'
import { Code } from '../../lib/Code.js'
import { Code } from '../../../lib/Code.js'
import type {
AnyClass,
AnyField,
Expand All @@ -17,15 +17,15 @@ import type {
Describable,
NamedNameToClass,
NameToClassNamedType,
} from '../../lib/graphql.js'
} from '../../../lib/graphql.js'
import {
getNodeDisplayName,
isDeprecatableNode,
isGraphQLOutputField,
type NameToClass,
unwrapToNonNull,
} from '../../lib/graphql.js'
import { entries, values } from '../../lib/prelude.js'
} from '../../../lib/graphql.js'
import { entries, values } from '../../../lib/prelude.js'
import type { Config } from './generateCode.js'

export const moduleNameSchemaBuildtime = `SchemaBuildtime`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
isScalarType,
isUnionType,
} from 'graphql'
import type { AnyClass, AnyGraphQLOutputField } from '../../lib/graphql.js'
import { hasMutation, hasQuery, hasSubscription, unwrapToNamed, unwrapToNonNull } from '../../lib/graphql.js'
import type { AnyClass, AnyGraphQLOutputField } from '../../../lib/graphql.js'
import { hasMutation, hasQuery, hasSubscription, unwrapToNamed, unwrapToNonNull } from '../../../lib/graphql.js'
import type { Config } from './generateCode.js'
import { moduleNameScalar } from './Scalar.js'

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { Formatter } from '@dprint/formatter'
import type { GraphQLObjectType, GraphQLSchema } from 'graphql'
import { buildSchema } from 'graphql'
import * as Path from 'node:path'
import type { TypeMapByKind } from '../../lib/graphql.js'
import { getTypeMapByKind } from '../../lib/graphql.js'
import type { TypeMapByKind } from '../../../lib/graphql.js'
import { getTypeMapByKind } from '../../../lib/graphql.js'
import { generateError } from './Error.js'
import { generateGlobal } from './global.js'
import { generateIndex } from './Index.js'
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/generator/files.ts → src/layers/2_generator/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getPath } from '@dprint/typescript'
import _ from 'json-bigint'
import fs from 'node:fs/promises'
import * as Path from 'node:path'
import { fileExists } from '../lib/prelude.js'
import { fileExists } from '../../lib/prelude.js'
import type { OptionsInput } from './code/generateCode.js'
import { generateCode, type Input as GenerateInput } from './code/generateCode.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TSError } from './lib/TSError.js'
import type { Schema } from './Schema/__.js'
import type { TSError } from '../../lib/TSError.js'
import type { Schema } from '../1_Schema/__.js'

declare global {
// todo some kind of distinct prefix
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/ban-types */

import { expectTypeOf, test } from 'vitest'
import type { Index } from '../../../tests/_/schema/generated/Index.js'
import type * as Schema from '../../../tests/_/schema/generated/SchemaBuildtime.js'
import type { Index } from '../../../../tests/_/schema/generated/Index.js'
import type * as Schema from '../../../../tests/_/schema/generated/SchemaBuildtime.js'
import type { SelectionSet } from '../SelectionSet/__.js'
import type { ResultSet } from './__.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable @typescript-eslint/ban-types */

import type { Simplify } from 'type-fest'
import type { ExcludeNull, GetKeyOr, SimplifyDeep } from '../../lib/prelude.js'
import type { TSError } from '../../lib/TSError.js'
import type { Schema, SomeField } from '../../Schema/__.js'
import type { PickScalarFields } from '../../Schema/Output/Output.js'
import type { ExcludeNull, GetKeyOr, SimplifyDeep } from '../../../lib/prelude.js'
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 '../SelectionSet/__.js'

export type Query<$SelectionSet extends object, $Index extends Schema.Index> = Root<$SelectionSet, $Index, 'Query'>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertType, expectTypeOf, test } from 'vitest'
import type { Index } from '../../../tests/_/schema/generated/Index.js'
import type { Index } from '../../../../tests/_/schema/generated/Index.js'
import type { SelectionSet } from './__.js'

type Q = SelectionSet.Query<Index>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable @typescript-eslint/ban-types */

import type { MaybeList, StringNonEmpty, Values } from '../../lib/prelude.js'
import type { TSError } from '../../lib/TSError.js'
import type { MaybeList, StringNonEmpty, Values } from '../../../lib/prelude.js'
import type { TSError } from '../../../lib/TSError.js'
import type {
InputFieldsAllNullable,
OmitNullableFields,
PickNullableFields,
Schema,
SomeField,
SomeFields,
} from '../../Schema/__.js'
} from '../../1_Schema/__.js'

export type Query<$Index extends Schema.Index> = Root<$Index, 'Query'>

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parse, print } from 'graphql'
import { describe, expect, test } from 'vitest'
import type { Index } from '../../../tests/_/schema/generated/Index.js'
import { $Index as schemaIndex } from '../../../tests/_/schema/generated/SchemaRuntime.js'
import type { Index } from '../../../../tests/_/schema/generated/Index.js'
import { $Index as schemaIndex } from '../../../../tests/_/schema/generated/SchemaRuntime.js'
import type { SelectionSet } from './__.js'
import type { Context } from './toGraphQLDocumentString.js'
import { rootTypeSelectionSet } from './toGraphQLDocumentString.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RootTypeName } from '../../lib/graphql.js'
import { lowerCaseFirstLetter } from '../../lib/prelude.js'
import { Schema } from '../../Schema/__.js'
import { readMaybeThunk } from '../../Schema/core/helpers.js'
import type { ReturnModeType } from '../Config.js'
import { RootTypeName } from '../../../lib/graphql.js'
import { lowerCaseFirstLetter } from '../../../lib/prelude.js'
import { Schema } from '../../1_Schema/__.js'
import { readMaybeThunk } from '../../1_Schema/core/helpers.js'
import type { ReturnModeType } from '../../4_client/Config.js'
import type { SelectionSet } from './__.js'
import { aliasPattern, fragmentPattern } from './SelectionSet.js'

Expand Down
8 changes: 4 additions & 4 deletions src/client/Config.ts → src/layers/4_client/Config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ExecutionResult } from 'graphql'
import type { GlobalRegistry } from '../globalRegistry.js'
import type { GraphQLExecutionResultError } from '../lib/graphql.js'
import type { SetProperty } from '../lib/prelude.js'
import type { Schema } from '../Schema/__.js'
import type { GraphQLExecutionResultError } from '../../lib/graphql.js'
import type { SetProperty } from '../../lib/prelude.js'
import type { Schema } from '../1_Schema/__.js'
import type { GlobalRegistry } from '../2_generator/globalRegistry.js'

export type ReturnModeType =
| ReturnModeTypeGraphQL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { OperationName } from '../lib/graphql.js'
import type { Exact } from '../lib/prelude.js'
import type { TSError } from '../lib/TSError.js'
import type { InputFieldsAllNullable, Schema } from '../Schema/__.js'
import type { OperationName } from '../../lib/graphql.js'
import type { Exact } from '../../lib/prelude.js'
import type { TSError } from '../../lib/TSError.js'
import type { InputFieldsAllNullable, Schema } from '../1_Schema/__.js'
import type { ResultSet } from '../3_IO/ResultSet/__.js'
import type { SelectionSet } from '../3_IO/SelectionSet/__.js'
import type {
AugmentRootTypeSelectionWithTypename,
Config,
Expand All @@ -10,8 +12,6 @@ import type {
ReturnModeRootField,
ReturnModeRootType,
} from './Config.js'
import type { ResultSet } from './ResultSet/__.js'
import type { SelectionSet } from './SelectionSet/__.js'

type RootTypeFieldContext = {
Config: Config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable */
import { beforeEach, describe, expect, test } from 'vitest'
import { db } from '../../tests/_/db.js'
import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js'
import { setupMockServer } from '../../tests/raw/__helpers.js'
import { db } from '../../../tests/_/db.js'
import { $Index as schemaIndex } from '../../../tests/_/schema/generated/SchemaRuntime.js'
import { setupMockServer } from '../../../tests/legacy/__helpers.js'
import { create } from './client.js'

const ctx = setupMockServer()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expectTypeOf, test } from 'vitest'
import * as Schema from '../../tests/_/schema/schema.js'
import * as SchemaMutationOnly from '../../tests/_/schemaMutationOnly/schema.js'
import * as SchemaQueryOnly from '../../tests/_/schemaQueryOnly/schema.js'
import * as Schema from '../../../tests/_/schema/schema.js'
import * as SchemaMutationOnly from '../../../tests/_/schemaMutationOnly/schema.js'
import * as SchemaQueryOnly from '../../../tests/_/schemaQueryOnly/schema.js'
import { create } from './client.js'

const client = create({ schema: Schema.schema, schemaIndex: Schema.$Index })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from 'vitest'
import { db } from '../../tests/_/db.js'
import { $Index } from '../../tests/_/schema/generated/SchemaRuntime.js'
import { schema } from '../../tests/_/schema/schema.js'
import { db } from '../../../tests/_/db.js'
import { $Index } from '../../../tests/_/schema/generated/SchemaRuntime.js'
import { schema } from '../../../tests/_/schema/schema.js'
import { create } from './client.js'

// todo test with custom scalars
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
import { expectTypeOf, test } from 'vitest'
import { isError } from '../../tests/_/schema/generated/Error.js'
import * as Schema from '../../tests/_/schema/schema.js'
import { isError } from '../../../tests/_/schema/generated/Error.js'
import * as Schema from '../../../tests/_/schema/schema.js'
import { create } from './client.js'

const client = create({ schema: Schema.schema, schemaIndex: Schema.$Index })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from 'vitest'
import { $Index } from '../../tests/_/schema/generated/SchemaRuntime.js'
import { schema } from '../../tests/_/schema/schema.js'
import { $Index } from '../../../tests/_/schema/generated/SchemaRuntime.js'
import { schema } from '../../../tests/_/schema/schema.js'
import { create } from './client.js'

test(`works`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { ExecutionResult } from 'graphql'
import { ObjMap } from 'graphql/jsutils/ObjMap.js'
import { describe } from 'node:test'
import { expectTypeOf, test } from 'vitest'
import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js'
import { schema } from '../../tests/_/schema/schema.js'
import { GraphQLExecutionResultError } from '../lib/graphql.js'
import { $Index as schemaIndex } from '../../../tests/_/schema/generated/SchemaRuntime.js'
import { schema } from '../../../tests/_/schema/schema.js'
import { GraphQLExecutionResultError } from '../../lib/graphql.js'
import { create } from './client.js'

// dprint-ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable */
import { describe, expect, test } from 'vitest'
import { db } from '../../tests/_/db.js'
import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js'
import { schema } from '../../tests/_/schema/schema.js'
import { __typename } from '../Schema/_.js'
import { db } from '../../../tests/_/db.js'
import { $Index as schemaIndex } from '../../../tests/_/schema/generated/SchemaRuntime.js'
import { schema } from '../../../tests/_/schema/schema.js'
import { __typename } from '../1_Schema/_.js'
import { create } from './client.js'

// dprint-ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
import { expectTypeOf, test } from 'vitest'
import * as Schema from '../../tests/_/schema/schema.js'
import { GraphQLExecutionResultError } from '../lib/graphql.js'
import * as Schema from '../../../tests/_/schema/schema.js'
import { GraphQLExecutionResultError } from '../../lib/graphql.js'
import { create } from './client.js'

const client = create({ schema: Schema.schema, schemaIndex: Schema.$Index })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from 'vitest'
import { db } from '../../tests/_/db.js'
import * as Schema from '../../tests/_/schema/schema.js'
import { db } from '../../../tests/_/db.js'
import * as Schema from '../../../tests/_/schema/schema.js'
import { create } from './client.js'

const client = create({ schema: Schema.schema, schemaIndex: Schema.$Index })
Expand Down
Loading