Skip to content

Commit

Permalink
Add support for inferring types from refs
Browse files Browse the repository at this point in the history
  • Loading branch information
hayes committed Sep 22, 2023
1 parent 3207dcc commit f8fb4e6
Show file tree
Hide file tree
Showing 54 changed files with 245 additions and 98 deletions.
6 changes: 6 additions & 0 deletions .changeset/smart-wasps-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@pothos/core': minor
'@pothos/deno': minor
---

Add support for $inferType and $inferInput helpers on Refs
4 changes: 4 additions & 0 deletions packages/core/src/refs/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export default class EnumRef<T, U = T>
{
override kind = 'Enum' as const;

$inferType!: T;

$inferInput!: U;

[outputShapeKey]!: T;

[inputShapeKey]!: U;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/refs/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default class FieldRef<T = unknown, Kind extends FieldKind = FieldKind> {

fieldName?: string;

$inferType!: T;

[outputFieldShapeKey]!: T;

constructor(kind: Kind, parentTypename: string) {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/refs/input-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export default class InputFieldRef<

argFor?: FieldRef | InputFieldRef;

$inferInput!: T;

[inputFieldShapeKey]!: T;

constructor(kind: Kind, parentTypename: string) {
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/refs/input-list.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { inputShapeKey, InputTypeParam, SchemaTypes } from '../types';
import BaseTypeRef from './base';

export default class InputObjectRef<Types extends SchemaTypes, T>
export default class InputListRef<Types extends SchemaTypes, T>
extends BaseTypeRef
implements PothosSchemaTypes.InputListRef<Types, T>
{
override kind = 'InputList' as const;

[inputShapeKey]!: T;

$inferInput!: T;

listType: InputTypeParam<Types>;

required: boolean;

constructor(listType: InputTypeParam<Types>, required: boolean) {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/refs/input-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export default class InputObjectRef<T>
{
override kind = 'InputObject' as const;

$inferInput!: T;

[inputShapeKey]!: T;

constructor(name: string) {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/refs/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import BaseTypeRef from './base';
export default class InputTypeRef<T> extends BaseTypeRef {
override kind;

$inferInput!: T;

[inputShapeKey]!: T;

constructor(kind: 'Enum' | 'InputObject' | 'Scalar', name: string) {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/refs/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export default class InterfaceRef<T, P = T>
{
override kind = 'Interface' as const;

$inferType!: T;

[outputShapeKey]!: T;

[parentShapeKey]!: P;

constructor(name: string) {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/refs/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ export default class ListRef<Types extends SchemaTypes, T, P = T>
{
override kind = 'List' as const;

$inferType!: T;

[outputShapeKey]!: T;

[parentShapeKey]!: P;

listType: TypeParam<Types>;

nullable: boolean;

constructor(listType: TypeParam<Types>, nullable: boolean) {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/refs/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export default class ObjectRef<T, P = T>
{
override kind = 'Object' as const;

$inferType!: T;

[outputShapeKey]!: T;

[parentShapeKey]!: P;

constructor(name: string) {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/refs/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import BaseTypeRef from './base';
export default class OutputTypeRef<T, P = T> extends BaseTypeRef {
override kind;

$inferType!: T;

[outputShapeKey]!: T;

[parentShapeKey]!: P;

constructor(kind: 'Enum' | 'Interface' | 'Object' | 'Scalar' | 'Union', name: string) {
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/refs/scalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ export default class ScalarRef<T, U, P = T>
{
override kind = 'Scalar' as const;

$inferType!: T;

$inferInput!: U;

[outputShapeKey]!: T;

[parentShapeKey]!: P;

[inputShapeKey]!: U;
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/refs/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export default class UnionRef<T, P = T>
{
override kind = 'Union' as const;

$inferType!: T;

[outputShapeKey]!: T;

[parentShapeKey]!: P;

constructor(name: string) {
Expand Down
5 changes: 4 additions & 1 deletion packages/deno/packages/core/builder.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/deno/packages/core/refs/enum.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/deno/packages/core/refs/field.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/deno/packages/core/refs/input-field.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/deno/packages/core/refs/input-list.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/deno/packages/core/refs/input-object.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/deno/packages/core/refs/input.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/deno/packages/core/refs/interface.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/deno/packages/core/refs/list.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/deno/packages/core/refs/object.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/deno/packages/core/refs/output.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/deno/packages/core/refs/scalar.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/deno/packages/core/refs/union.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/deno/packages/core/types/builder-options.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/deno/packages/core/types/global/type-options.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 19 additions & 8 deletions packages/deno/packages/core/types/utils.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions packages/deno/packages/core/utils/base64.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/deno/packages/plugin-add-graphql/global-types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/deno/packages/plugin-add-graphql/schema-builder.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

1 comment on commit f8fb4e6

@vercel
Copy link

@vercel vercel bot commented on f8fb4e6 Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.