goldcaddy77/warthog

Fetching typed json fields

metmirr opened this issue · 7 comments

Resolvers don't fetch typed json fields when a resolver function has the @Fields parameter. The example below is taken from examples/02:

  @Query(() => [User])
  async users(
    @Args() { where, orderBy, limit, offset }: UserWhereArgs,
    @Fields() fields: string[]
  ): Promise<User[]> {}

image

@metmirr Are you sure that record has a value in the DB?

Yes, I am. Resolver without @Fields argument return this data:

image

Fixed in #467

Note that I needed to update the behavior of the Fields decorator to include all top-level fields. This will bring along both JSON fields as well as associations. Then BaseModel makes sure all values passed into find are actually fields on the table. This is technically a breaking change - but I'd argue the Fields decorator wasn't really working as designed anyway. Do you think this is ok, or should I create a new decorator with the new behavior?

I've merged this. Feel free to play around and let me know if you think anything needs to be tweaked.

Note that I needed to update the behavior of the Fields decorator to include all top-level fields. This will bring along both JSON fields as well as associations. Then BaseModel makes sure all values passed into find are actually fields on the table. This is technically a breaking change - but I'd argue the Fields decorator wasn't really working as designed anyway. Do you think this is ok, or should I create a new decorator with the new behavior?

I think this is it, the decorator is working as expected with jsons, relations etc.

I've merged this. Feel free to play around and let me know if you think anything needs to be tweaked.

Working perfectly as expected, thank you so much! Really appreciated!