prismake / typegql

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

boolean Field gets returned as null instead of false #28

Closed capaj closed 6 years ago

capaj commented 6 years ago

I use typegql with objection.js model, on this model I have a Field like this:

@ObjectType
class WorkspaceModel extends TimestampedModel {
  static tableName = 'workspaces'
  @Field() readonly id!: number
  @Field() user_id: number
  @Field() name: string
  @Field()
  is_open: boolean
}

This is the WorkspaceModel object I am returning in my Query :

{
      "id": 3,
      "is_open": false,
      "name": "Workspace from test",
      "openEnrolmentCount": 0,
      "role": "OWNER",
      "topicsCount": 0,
    }

this is what I get from graphql:

{
      "id": 3,
      "is_open": null,
      "name": "Workspace from test",
      "openEnrolmentCount": 0,
      "role": "OWNER",
      "topicsCount": 0,
    }

So I ran a test in my boilerplate an indeed using this schema:

@ObjectType({ description: 'Simple product object type' })
class Product extends Model {
  @Field() is_open: boolean
}

@SchemaRoot()
class SuperSchema {
  @Query({ type: Product, isNullable: false })
  prod(): Product {
    const product = new Product()
    product.is_open = false
    return product
  }
}

image

when the field is true it is returned correctly.

capaj commented 6 years ago

@pie6k I have a fix ready, but it sits on top of prettier branch, can you merge it? I'd open the fix after it's merged.

pie6k commented 6 years ago

@capaj I've merged prettier branch