Don't select the whole table
Is your feature request related to a problem? Please describe.
The following query pulls the whole posts table in memory:
query{ posts{ id } }
If there are a large number of posts with large content, this can be an issue.
Describe the solution you'd like Transform the selected graphql fields into prisma select and pass it to the prisma client.
Additional context https://github.com/paljs/prisma-tools/blob/main/packages/plugins/src/select.ts
This can be only opt-in because you may have field resolvers that depend on some not requested fields.
@MichalLytek would you consider an exclude feature or something? I have one table which is large but I only need a small bit of it. Trying to find best way to exclude a certain field from the prisma query
You can always eject and use your custom resolver instead of the single generated one.
You may use following approach to query only for choosen fields in your custom resolver. It works fine till you work on one table.
import graphqlFields from 'graphql-fields';
...
@TypeGraphQL.Resolver(_of => SomeTable)
...
// Build prisma select object based on graphql query fileds
const select = Object.keys(
graphqlFields(info, {}, { excludedFields: ['__typename'] }),
).reduce(
(acc, key) => ({
...acc,
...{ [key]: true },
}),
{},
);
return getPrismaFromContext(ctx).sometable.findMany({
...args,
select
});