Skip to content

Commit

Permalink
refactor: schema standard types
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Oct 21, 2024
1 parent c29c877 commit 9e5a0ad
Show file tree
Hide file tree
Showing 47 changed files with 89 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/entrypoints/_Scalars.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { create } from '../types/Schema/types/Scalar/_.js'
export { create } from '../types/Schema/nodes/Scalar/_.js'
2 changes: 1 addition & 1 deletion src/entrypoints/generator-helpers/standardScalarTypes.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from '../../types/Schema/types/Scalar/standardScalarTypes.js'
export * from '../../types/Schema/StandardTypes/scalar.js'
2 changes: 1 addition & 1 deletion src/entrypoints/utilities-for-generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export { type Exact, type ExactNonEmpty, type UnionExpanded } from '../lib/prelu
export { TypeFunction } from '../lib/type-function/__.js'
export { type GlobalRegistry } from '../types/GlobalRegistry/GlobalRegistry.js'
export { Schema } from '../types/Schema/__.js'
export * from '../types/Schema/types/Scalar/standardScalarTypes.js'
export * from '../types/Schema/StandardTypes/scalar.js'
export { type SchemaDrivenDataMap } from '../types/SchemaDrivenDataMap/__.js'
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default Generator
libraryPaths: {
client: `../../../../entrypoints/client.ts`,
schema: `../../../../entrypoints/schema.ts`,
scalars: `../../../../types/Schema/types/Scalar/standardScalarTypes.ts`,
scalars: `../../../../types/Schema/StandardTypes/scalar.ts`,
utilitiesForGenerated: `../../../../entrypoints/utilities-for-generated.ts`,
},
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as $$Utilities from '../../../../../../entrypoints/utilities-for-generated.js'

export * from '../../../../../../types/Schema/types/Scalar/standardScalarTypes.js'
export * from '../../../../../../types/Schema/StandardTypes/scalar.js'

//
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export namespace Schema {
//
//

export type Mutation = $.ObjectMutation<{
export type Mutation = $.StandardTypes.Mutation<{
id: $.Field<'id', $.Nullable<$Scalar.ID>, null>
idNonNull: $.Field<'idNonNull', $Scalar.ID, null>
}>

export type Query = $.ObjectQuery<{
export type Query = $.StandardTypes.Query<{
InputObjectNested: $.Field<
'InputObjectNested',
$.Nullable<$Scalar.ID>,
Expand Down
2 changes: 1 addition & 1 deletion src/generator/generators/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const concreteRenderers = defineConcreteRenderers({
GraphQLObjectType: (config, node) => {
const maybeRootTypeName = (Grafaid.Schema.RootTypeName as Record<string, Grafaid.Schema.RootTypeName>)[node.name]
const type = maybeRootTypeName
? `$.Object${maybeRootTypeName}<${renderOutputFields(config, node)}>`
? `$.StandardTypes.${maybeRootTypeName}<${renderOutputFields(config, node)}>`
: `$.OutputObject<${Code.string(node.name)}, ${renderOutputFields(config, node)}>`
const doc = getDocumentation(config, node)
const source = Code.export$(Code.type(node.name, type))
Expand Down
2 changes: 1 addition & 1 deletion src/layers/3_InferResult/Object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type SelectionNonSelectAlias<$SelectionSet , $Schema extends Schema, $SchemaNode

// dprint-ignore
export namespace Errors {
export type UnknownFieldName<$FieldName extends string, $Object extends Schema.RootType | Schema.OutputObject> =
export type UnknownFieldName<$FieldName extends string, $Object extends Schema.StandardTypes.RootType | Schema.OutputObject> =
TSErrorDescriptive<'Object', `field "${$FieldName}" does not exist on object "${$Object['fields']['__typename']['type']['type']}"`>
}

Expand Down
2 changes: 1 addition & 1 deletion src/layers/3_InferResult/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Object } from './Object.js'
export type RootViaObject<
$SelectionSet,
$Schema extends Schema,
$RootType extends Schema.RootType,
$RootType extends Schema.StandardTypes.RootType,
> = Root<
$SelectionSet,
$Schema,
Expand Down
2 changes: 2 additions & 0 deletions src/types/Schema/StandardTypes/_.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './object.js'
export * from './scalar.js'
1 change: 1 addition & 0 deletions src/types/Schema/StandardTypes/__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as StandardTypes from './_.js'
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { Grafaid } from '../../lib/grafaid/__.js'
import type { OutputObject, SomeFields } from './_.js'
import type { Grafaid } from '../../../lib/grafaid/__.js'
import type { OutputObject, SomeFields } from '../_.js'

export interface ObjectQuery<
export interface Query<
$Fields extends SomeFields = SomeFields,
> extends OutputObject<Grafaid.Schema.RootTypeNameQuery, $Fields> {}

export interface ObjectMutation<
export interface Mutation<
$Fields extends SomeFields = SomeFields,
> extends OutputObject<Grafaid.Schema.RootTypeNameMutation, $Fields> {}

export interface ObjectSubscription<
export interface Subscription<
$Fields extends SomeFields = SomeFields,
> extends OutputObject<Grafaid.Schema.RootTypeNameSubscription, $Fields> {}

export type RootType = ObjectQuery | ObjectMutation | ObjectSubscription
export type RootType = Query | Mutation | Subscription
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import { create } from './create.js'
import { JavaScriptScalarCodecs } from './JavaScriptScalarCodecs.js'
import { createCodec } from '../nodes/Scalar/codec.js'
import { create } from '../nodes/Scalar/create.js'

export const JavaScriptScalarCodecs = {
String: createCodec({
encode: (value: string) => value,
decode: (value: string) => value,
}),
Number: createCodec({
encode: (value: number) => value,
decode: (value: number) => value,
}),
Boolean: createCodec({
encode: (value: boolean) => value,
decode: (value: boolean) => value,
}),
}

export const String = create(`String`, JavaScriptScalarCodecs.String)

Expand Down
26 changes: 13 additions & 13 deletions src/types/Schema/_.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export * as Directives from './Directive.js'
export * from './helpers.js'
export * from './Named/__.js'
export * from './nodes/__typename.js'
export * from './nodes/Args.js'
export * from './nodes/Enum.js'
export * from './nodes/InputField.js'
export * from './nodes/InputObject.js'
export * from './nodes/Interface.js'
export * from './nodes/List.js'
export * from './nodes/Nullable.js'
export * from './nodes/OutputField.js'
export { type OutputObject } from './nodes/OutputObject.js'
export * from './nodes/Scalar/Scalar.js'
export * from './nodes/Union.js'
export * from './StandardTypes/__.js'
export * from './typeGroups.js'
export * from './types/__typename.js'
export * from './types/Args.js'
export * from './types/Enum.js'
export * from './types/InputField.js'
export * from './types/InputObject.js'
export * from './types/Interface.js'
export * from './types/List.js'
export * from './types/Nullable.js'
export * from './types/OutputField.js'
export { type OutputObject } from './types/OutputObject.js'
export * from './types/Scalar/Scalar.js'
export * from './types/Union.js'
export * from './typeTypes.js'
22 changes: 11 additions & 11 deletions src/types/Schema/__.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export * as Schema from './_.js'

import type { GlobalRegistry } from '../GlobalRegistry/GlobalRegistry.js'
import type { Enum } from './types/Enum.js'
import type { Interface } from './types/Interface.js'
import type { OutputObject } from './types/OutputObject.js'
import type { Scalar } from './types/Scalar/Scalar.js'
import type { Union } from './types/Union.js'
import type { ObjectMutation, ObjectQuery, ObjectSubscription, RootType } from './typeTypes.js'
import type { Enum } from './nodes/Enum.js'
import type { Interface } from './nodes/Interface.js'
import type { OutputObject } from './nodes/OutputObject.js'
import type { Scalar } from './nodes/Scalar/Scalar.js'
import type { Union } from './nodes/Union.js'
import type { Mutation, Query, RootType, Subscription } from './StandardTypes/object.js'

/**
* A generic schema type. Any particular schema will be a subtype of this, with
Expand All @@ -20,15 +20,15 @@ export interface Schema<
RootTypesPresent: ('Query' | 'Mutation' | 'Subscription')[]
RootUnion: RootType
Root: {
Query: null | ObjectQuery
Mutation: null | ObjectMutation
Subscription: null | ObjectSubscription
Query: null | Query
Mutation: null | Mutation
Subscription: null | Subscription
}
allTypes: Record<
string,
| Enum
| ObjectQuery
| ObjectMutation
| Query
| Mutation
| OutputObject
| Union
| Interface
Expand Down
2 changes: 1 addition & 1 deletion src/types/Schema/directives/Include.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Directive } from '../Directive.js'
import { Scalar } from '../types/Scalar/Scalar.js'
import { Scalar } from '../nodes/Scalar/Scalar.js'

export const IncludeDirective: Directive = {
name: `include`,
Expand Down
2 changes: 1 addition & 1 deletion src/types/Schema/directives/Skip.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Directive } from '../Directive.js'
import { Scalar } from '../types/Scalar/Scalar.js'
import { Scalar } from '../nodes/Scalar/Scalar.js'

export const SkipDirective: Directive = {
name: `skip`,
Expand Down
6 changes: 3 additions & 3 deletions src/types/Schema/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { TSErrorDescriptive } from '../../lib/ts-error.js'
import type { __typename } from './nodes/__typename.js'
import type { List } from './nodes/List.js'
import type { Nullable } from './nodes/Nullable.js'
import type { NamedTypes } from './typeGroups.js'
import type { __typename } from './types/__typename.js'
import type { List } from './types/List.js'
import type { Nullable } from './types/Nullable.js'

// todo extends any because of infinite depth issue in generated schema types
// dprint-ignore
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.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions src/types/Schema/nodes/Scalar/_.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from '../../StandardTypes/scalar.js'
export * from '../ScalarCodecless.js'
export * from './create.js'
export * from './helpers.js'
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { String } from '../../StandardTypes/scalar.js'
import type { Mapper } from './codec.js'
import type { Scalar } from './Scalar.js'
import { String } from './standardScalarTypes.js'

export type GetEncoded<$Scalar> = $Scalar extends Scalar<infer _, infer _, infer $Encoded> ? $Encoded : never

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions src/types/Schema/typeGroups.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { InputObject } from './_.js'
import type { __typename } from './types/__typename.js'
import type { Enum } from './types/Enum.js'
import type { Interface } from './types/Interface.js'
import type { List } from './types/List.js'
import type { Nullable } from './types/Nullable.js'
import type { OutputObject } from './types/OutputObject.js'
import type { Scalar } from './types/Scalar/Scalar.js'
import type { Union } from './types/Union.js'
import type { __typename } from './nodes/__typename.js'
import type { Enum } from './nodes/Enum.js'
import type { Interface } from './nodes/Interface.js'
import type { List } from './nodes/List.js'
import type { Nullable } from './nodes/Nullable.js'
import type { OutputObject } from './nodes/OutputObject.js'
import type { Scalar } from './nodes/Scalar/Scalar.js'
import type { Union } from './nodes/Union.js'

export type NamedTypes = NamedInputTypes | NamedOutputTypes

Expand Down
16 changes: 0 additions & 16 deletions src/types/Schema/types/Scalar/JavaScriptScalarCodecs.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/types/Schema/types/Scalar/_.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tests/_/schemas/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const generate = async (
libraryPaths: {
client: `../../../src/entrypoints/client.ts`,
schema: `../../../src/entrypoints/schema.ts`,
scalars: `../../../src/types/Schema/types/Scalar/standardScalarTypes.ts`,
scalars: `../../../src/types/Schema/StandardTypes/scalar.ts`,
utilitiesForGenerated: `../../../src/entrypoints/utilities-for-generated.ts`,
},
...input.input,
Expand Down
2 changes: 1 addition & 1 deletion tests/_/schemas/kitchen-sink/graffle/modules/Scalar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as $$Utilities from '../../../../../../src/entrypoints/utilities-for-generated.js'

export * from '../../../../../../src/types/Schema/types/Scalar/standardScalarTypes.js'
export * from '../../../../../../src/types/Schema/StandardTypes/scalar.js'

//
//
Expand Down
4 changes: 2 additions & 2 deletions tests/_/schemas/kitchen-sink/graffle/modules/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export namespace Schema {
//
//

export type Mutation = $.ObjectMutation<{
export type Mutation = $.StandardTypes.Mutation<{
id: $.Field<'id', $.Nullable<$Scalar.ID>, null>
idNonNull: $.Field<'idNonNull', $Scalar.ID, null>
}>

export type Query = $.ObjectQuery<{
export type Query = $.StandardTypes.Query<{
InputObjectNested: $.Field<
'InputObjectNested',
$.Nullable<$Scalar.ID>,
Expand Down
2 changes: 1 addition & 1 deletion tests/_/schemas/mutation-only/graffle/modules/Scalar.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type * as $$Utilities from '../../../../../../src/entrypoints/utilities-for-generated.js'

export * from '../../../../../../src/types/Schema/types/Scalar/standardScalarTypes.js'
export * from '../../../../../../src/types/Schema/StandardTypes/scalar.js'
2 changes: 1 addition & 1 deletion tests/_/schemas/mutation-only/graffle/modules/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export namespace Schema {
//
//

export type Mutation = $.ObjectMutation<{
export type Mutation = $.StandardTypes.Mutation<{
id: $.Field<'id', $.Nullable<$Scalar.ID>, null>
idNonNull: $.Field<'idNonNull', $Scalar.ID, null>
}>
Expand Down
2 changes: 1 addition & 1 deletion tests/_/schemas/pokemon/graffle/modules/Scalar.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type * as $$Utilities from '../../../../../../src/entrypoints/utilities-for-generated.js'

export * from '../../../../../../src/types/Schema/types/Scalar/standardScalarTypes.js'
export * from '../../../../../../src/types/Schema/StandardTypes/scalar.js'
4 changes: 2 additions & 2 deletions tests/_/schemas/pokemon/graffle/modules/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export namespace Schema {
//
//

export type Mutation = $.ObjectMutation<{
export type Mutation = $.StandardTypes.Mutation<{
addPokemon: $.Field<
'addPokemon',
$.Nullable<Pokemon>,
Expand All @@ -34,7 +34,7 @@ export namespace Schema {
>
}>

export type Query = $.ObjectQuery<{
export type Query = $.StandardTypes.Query<{
battles: $.Field<'battles', $.List<Battle>, null>
beings: $.Field<'beings', $.List<Being>, null>
pokemon: $.Field<'pokemon', $.Nullable<$.List<Pokemon>>, null>
Expand Down
2 changes: 1 addition & 1 deletion tests/_/schemas/query-only/graffle/modules/Scalar.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type * as $$Utilities from '../../../../../../src/entrypoints/utilities-for-generated.js'

export * from '../../../../../../src/types/Schema/types/Scalar/standardScalarTypes.js'
export * from '../../../../../../src/types/Schema/StandardTypes/scalar.js'
2 changes: 1 addition & 1 deletion tests/_/schemas/query-only/graffle/modules/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export namespace Schema {
//
//

export type Query = $.ObjectQuery<{
export type Query = $.StandardTypes.Query<{
id: $.Field<'id', $.Nullable<$Scalar.ID>, null>
idNonNull: $.Field<'idNonNull', $Scalar.ID, null>
}>
Expand Down

0 comments on commit 9e5a0ad

Please sign in to comment.