prismake / typegql

Create GraphQL schema with TypeScript classes.
https://prismake.github.io/typegql/
MIT License
424 stars 21 forks source link

fields defined on a third level and farther of function prototype chain are not registered into schema #42

Closed capaj closed 6 years ago

capaj commented 6 years ago

I've got:

@ObjectType()
class TimestampedModel extends Model {
  @Field({ type: GraphQLDateTime })
  created_at: Date
  @Field({ type: GraphQLDateTime })
  updated_at: Date
}

@ObjectType({ description: 'Simple product object type' })
class Product extends TimestampedModel {
  @Field({ type: String })
  name: string

  @Field({ type: Number })
  price: number

  @After(() => {
    console.log('arguments', arguments)
  })
  @Field()
  get wow(): number {
    return 10
  }

  @Field() is_open: boolean
}

@ObjectType()
class UberProduct extends Product {
  @Field({ type: String })
  name2: string
}

@ObjectType()
class ExtraUberProduct extends UberProduct {
  @Field({ type: String })
  name3: string
}

@SchemaRoot()
class SuperSchema {
  @Query({ type: String })
  hello(name: string): boolean {
    return false
  }
  @Query({ type: ExtraUberProduct, isNullable: false })
  prod(): ExtraUberProduct {
    const product = new ExtraUberProduct()
    product.name = 'name'
    product.price = 5
    product.is_open = false
    return product
  }
}

const schema = compileSchema({ roots: [SuperSchema] })
console.log('schema: ', printSchema(schema))

the output is:

schema:  type ExtraUberProduct {
  name2: String
  name3: String
}

type Query {
  hello(name: String!): String
  prod: ExtraUberProduct!
}

I expect it to be:

schema:  type ExtraUberProduct {
  created_at: DateTime
  updated_at: DateTime
  name: String
  price: Float
  wow: Float
  is_open: Boolean
  name2: String
  name3: String
}

type Query {
  hello(name: String!): String
  prod: ExtraUberProduct!
}
capaj commented 6 years ago

BTW just for fun I've tried if this works in type-graphql library and it does.

pie6k commented 6 years ago

Fixed by https://github.com/prismake/typegql/pull/43 by @capaj - thanks!