goldcaddy77 / warthog

GraphQL API Framework with strong conventions and auto-generated schema
https://warthog.dev/
MIT License
359 stars 38 forks source link

Fetching typed json fields #464

Closed metmirr closed 3 years ago

metmirr commented 3 years ago

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

goldcaddy77 commented 3 years ago

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

metmirr commented 3 years ago

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

image

goldcaddy77 commented 3 years ago

Fixed in https://github.com/goldcaddy77/warthog/pull/467

goldcaddy77 commented 3 years ago

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?

goldcaddy77 commented 3 years ago

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

metmirr commented 3 years ago

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.

metmirr commented 3 years ago

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!