Skip to content

Commit

Permalink
Moved description and deprecated to abstract class
Browse files Browse the repository at this point in the history
  • Loading branch information
mishushakov committed Jun 5, 2023
1 parent 98e56e6 commit 1edb124
Showing 1 changed file with 10 additions and 125 deletions.
135 changes: 10 additions & 125 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ export abstract class Type<T, X extends GarphType> {
_args?: Args
_shape: T
typeDef: TypeDefinition<T>

description(text: string) {
this.typeDef.description = text
return this
}

deprecated(reason: string) {
this.typeDef.deprecated = reason
return this
}
}

export type TypeDefinition<T> = {
Expand Down Expand Up @@ -161,11 +171,6 @@ class GType<N extends string, T extends AnyTypes> extends Type<T, 'ObjectType'>
}
}

description(text: string) {
this.typeDef.description = text
return this
}

implements<D extends AnyInterface>(ref: D | D[]) {
// This is temporary construct, until we figure out how to properly manage to shared schema
this.typeDef.interfaces = Array.isArray(ref) ? ref : [ref]
Expand All @@ -184,11 +189,6 @@ class GInput<N extends string, T extends AnyTypes> extends Type<T, 'InputType'>
shape
}
}

description(text: string) {
this.typeDef.description = text
return this
}
}

class GInterface<N extends string, T extends AnyTypes> extends Type<T, 'InterfaceType'> {
Expand All @@ -204,11 +204,6 @@ class GInterface<N extends string, T extends AnyTypes> extends Type<T, 'Interfac
}
}

description(text: string) {
this.typeDef.description = text
return this
}

implements<D extends AnyInterface>(ref: D | D[]) {
// This is temporary construct, until we figure out how to properly manage to shared schema
this.typeDef.interfaces = Array.isArray(ref) ? ref : [ref]
Expand Down Expand Up @@ -237,21 +232,11 @@ class GString<T extends GarphType> extends Type<string, T> {
return new GList<this>(this)
}

description(text: string) {
this.typeDef.description = text
return this
}

default(value: string) {
this.typeDef.defaultValue = value
return this
}

deprecated(reason: string) {
this.typeDef.deprecated = reason
return this
}

omitResolver () {
return new GOmitResolver<this>(this)
}
Expand Down Expand Up @@ -282,21 +267,11 @@ class GNumber<T extends GarphType> extends Type<number, T> {
return new GList<this>(this)
}

description(text: string) {
this.typeDef.description = text
return this
}

default(value: number) {
this.typeDef.defaultValue = value
return this
}

deprecated(reason: string) {
this.typeDef.deprecated = reason
return this
}

omitResolver () {
return new GOmitResolver<this>(this)
}
Expand Down Expand Up @@ -327,21 +302,11 @@ class GBoolean extends Type<boolean, 'Boolean'> {
return new GList<this>(this)
}

description(text: string) {
this.typeDef.description = text
return this
}

default(value: boolean) {
this.typeDef.defaultValue = value
return this
}

deprecated(reason: string) {
this.typeDef.deprecated = reason
return this
}

omitResolver () {
return new GOmitResolver<this>(this)
}
Expand Down Expand Up @@ -371,11 +336,6 @@ class GEnum<N extends string, T extends readonly string[] | TSEnumType> extends
shape: enumShape
}
}

description(text: string) {
this.typeDef.description = text
return this
}
}

class GUnion<N extends string, T extends AnyObjects> extends Type<T, 'Union'> {
Expand All @@ -390,11 +350,6 @@ class GUnion<N extends string, T extends AnyObjects> extends Type<T, 'Union'> {
shape
}
}

description(text: string) {
this.typeDef.description = text
return this
}
}

class GRef<T> extends Type<T, 'Ref'> {
Expand Down Expand Up @@ -425,21 +380,11 @@ class GRef<T> extends Type<T, 'Ref'> {
return new GPaginatedList<this>(this)
}

description(text: string) {
this.typeDef.description = text
return this
}

default(value: InferRaw<this['_inner']>) {
this.typeDef.defaultValue = value
return this
}

deprecated(reason: string) {
this.typeDef.deprecated = reason
return this
}

omitResolver () {
return new GOmitResolver<this>(this)
}
Expand All @@ -461,16 +406,6 @@ class GScalar<I, O> extends Type<I, 'Scalar'> {
}
}

description(text: string) {
this.typeDef.description = text
return this
}

deprecated(reason: string) {
this.typeDef.deprecated = reason
return this
}

specifiedByUrl(url: string) {
this.typeDef.scalarOptions.specifiedByUrl = url
return this
Expand All @@ -495,21 +430,11 @@ class GList<T extends AnyType> extends Type<T, 'List'> {
return this
}

description(text: string) {
this.typeDef.description = text
return this
}

default(value: typeof this._inner) {
this.typeDef.defaultValue = value
return this
}

deprecated(reason: string) {
this.typeDef.deprecated = reason
return this
}

omitResolver () {
return new GOmitResolver<this>(this)
}
Expand Down Expand Up @@ -554,16 +479,6 @@ class GPaginatedList<T extends AnyType> extends Type<T, 'PaginatedList'> {
return this
}

description(text: string) {
this.typeDef.description = text
return this
}

deprecated(reason: string) {
this.typeDef.deprecated = reason
return this
}

omitResolver () {
return new GOmitResolver<this>(this)
}
Expand All @@ -589,21 +504,11 @@ class GOptional<T extends AnyType> extends Type<T, 'Optional'> {
return new GList<this>(this)
}

description(text: string) {
this.typeDef.description = text
return this
}

default(value: InferRaw<T>) {
this.typeDef.defaultValue = value
return this
}

deprecated(reason: string) {
this.typeDef.deprecated = reason
return this
}

omitResolver () {
return new GOmitResolver<this>(this)
}
Expand All @@ -628,21 +533,11 @@ class GOmitResolver<T extends AnyType> extends Type<T, 'OmitResolver'> {
return this
}

description(text: string) {
this.typeDef.description = text
return this
}

default(value: InferRaw<T>) {
this.typeDef.defaultValue = value
return this
}

deprecated(reason: string) {
this.typeDef.deprecated = reason
return this
}

args<X extends Args>(args: X) {
return new GArgs<this, X>(this, args)
}
Expand All @@ -660,16 +555,6 @@ class GArgs<T extends AnyType, X extends Args> extends Type<T, 'Args'> {
this.typeDef = shape.typeDef
this.typeDef.args = args
}

description(text: string) {
this.typeDef.description = text
return this
}

deprecated(reason: string) {
this.typeDef.deprecated = reason
return this
}
}

export class GarphSchema {
Expand Down

0 comments on commit 1edb124

Please sign in to comment.