Comments (6)
Hi,
Is this needed every time you query the parent type or in only some query
if you can do this at the query level we have a way
https://paljs.com/plugins/select#mergedeep
from prisma-tools.
Hi,
Is this needed every time you query the parent type or in only some query if you can do this at the query level we have a way
It looks like I can't do it at the query level easily because the "parent" is not always at the root of the query, sometimes there is a parent above it.
Why can't I return also a "mergeDeep" object in the defaultFields ?
because I don't have an as convenient way of checking a field in the query exists than with the (select) handler of the defaultFields object, and that is what I would need to enhance the prisma generated select with my new mergeDeep Object
from prisma-tools.
Look at this code and see how we can do this we are filtering the input fields to remove the fields not in the prisma model.
We add the default fields you send but after that, we overwrite them with the child-filtered fields you can check if you have any way
prisma-tools/packages/plugins/src/select.ts
Line 256 in c5c0661
Also, look at the line 284
from prisma-tools.
@ResolveField()
exercises(@Args() args: FindManySportExerciseArgs, @Info() info) {
const select = new PrismaSelect(info, {
defaultFields,
});
const originalQuery = select.valueWithFilter('');
let selectValue = select.value;
if (originalQuery?.select?.title) {
selectValue = PrismaSelect.mergeDeep(selectValue, {
select: {
simpleExercise: {
select: {
title: true,
},
},
},
});
}
return this.sportExercisesService.findMany(args, selectValue);
}
I have done that, but it doesn't feel very efficient.
isn't there a way to do this like defaultFields, so that I don't have to add this piece of code on every CRUD resolvers .. ?
from prisma-tools.
I am thinking on away to do the merge between default fields and the requested
But for now you can for easy way always query simpleExercise.title by adding it to default fields direct without any conditions
from prisma-tools.
Unfortunately, I am not querying simpleExercise, so even if I add title, it is not queried in my original request.
And even if I add simpleExercise: true to the parent type, I have another use case where I have one more nested level which is starting to make this really inefficient.
What I am think now, is to create an helper method that generate the PrismaSelect AND apply a given mergeDeep object based on some kind of logic similar to the defaultFields one. However, as of today, I am relying on this to determine if the computed field is requested :
const originalQuery = select.valueWithFilter('');
if (originalQuery?.select?.title) {
}
which works only if the compute field is at the parent level.
What would be great, would be to be able to generate directly from the defaultFields object, not only a parent-level fields flat object but also a mergeDeep compatible one that would be applied automatically or manually. And then we could easily add general logic to query nested fields based on a parent field condition.
I am thinking of doing that manually but I don't think there is an easy way to check if a given field is present on a given GraphQL type with prisma-tools, you for sure do that already within the library but no method of this kind is exposed appart from the defaultFields which is not flexible enough. I am also thinking of doing that manually, but then we would be analyzing the graphQL twice (1 within prisma-tools and once more with my code).
I really think that there is some kind of easy fix to that, as it seems you already do everything, but I don't know the inside of prisma-tool enough to expose the appropriate method.
from prisma-tools.
Related Issues (20)
- Support Prisma 5.0.0 version HOT 6
- `__typename` not returned in select HOT 2
- TypeError: Cannot read properties of undefined (reading 'includes')
- Error: pal config file is not found HOT 1
- PrismaSelect - `Record<string, unknown> ` instead of `any`
- [sdl generator] Error when model name is in lower case HOT 1
- Convert to Camel case breaks when tables start with same name
- problems using arguments in a subquery
- _count doesn't accept arguments
- Aggregate resolver return type is wrong
- Utils has some Typescript errors
- Test in utils fails on Windows
- VS Code settings should include PNPM as the package manager
- Get object first -> Ignore nested object
- TypeError: The "to" argument must be of type string. Received an instance of Object. Code: `ERR_INVALID_ARG_TYPE` HOT 3
- @prisma/internals >= 5.15.0 missing getSchemaPath - breaks utils package HOT 3
- createManyAndReturn types not what Pal.js is expecting HOT 3
- Tests fail on Windows
- Does not convert PascalCase field names to camelCase
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prisma-tools.