Git Product home page Git Product logo

Comments (6)

AhmedElywa avatar AhmedElywa commented on September 27, 2024

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.

cyril94440 avatar cyril94440 commented on September 27, 2024

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

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.

AhmedElywa avatar AhmedElywa commented on September 27, 2024

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

if (this.defaultFields && this.defaultFields[modelName]) {

Also, look at the line 284

from prisma-tools.

cyril94440 avatar cyril94440 commented on September 27, 2024
@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.

AhmedElywa avatar AhmedElywa commented on September 27, 2024

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.

cyril94440 avatar cyril94440 commented on September 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.