Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latency/codegen issue with additional fields to generated entities #206

Open
okaisti opened this issue Feb 4, 2024 · 0 comments
Open

latency/codegen issue with additional fields to generated entities #206

okaisti opened this issue Feb 4, 2024 · 0 comments

Comments

@okaisti
Copy link

okaisti commented Feb 4, 2024

Hi, I've found 2 suggested ways to add additional fields to a generated entity, neither works in an ideal way.

  1. extending a class (Using custom types when generating #164 (comment))

  2. with ResolveReference ([Question] Custom extra field not in Prisma Schema #117 (comment))

for 1), this does not work when the entity is being referenced by other entities (prisma references etc), resulting in
"Error: Schema must contain uniquely named types but contains multiple types named "X"."

for 2), this actually adds massive latency overhead to larger queries (10000 records) screenshotted traces below. the additional overhead comes from nests/apollo, but as the field is already fetched form the db, we should be talking about latencies in μs.

nestjs does not support graphql "extend" directive, so thats not an option either, i guess the only workaround here is to make a separate "ExtendedEntity extends Entity" and query that instead, but that "duplicates" the schema.

Screenshot 2024-02-04 at 13 00 16

My use-case, is that i am "extending" an entity and adding fields to it, and joining them in a raw-query, the fields are already present, but having to add "Resolvefield" fields adds additional 2 seconds to the request.

I think this lib needs a way to add additional fields. e.g. with comments in the prisma schema file

Here is an example of the current "problematic" setup:

@Resolver(() => Example)
export class ExampleResolver {
  ....
  @ResolveField(() => String, { nullable: true })
  additional_field_1(@Parent() { additional_field_1 }: ExtendedExample): string | null {
    return additional_field_1;
  }

  @ResolveField(() => String, { nullable: true })
  additional_field_2(@Parent() { additional_field_2 }: ExtendedExample): string | null {
    return additional_field_2;
  }

  @ResolveField(() => String, { nullable: true })
  additional_field_3(@Parent() { additional_field_3 }: ExtendedExample): string | null {
    return additional_field_3;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant