Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Missing relationship fields with many in Database API find query results #7198

Closed
MurzNN opened this issue Jan 17, 2022 · 3 comments · May be fixed by #7204
Closed

Missing relationship fields with many in Database API find query results #7198

MurzNN opened this issue Jan 17, 2022 · 3 comments · May be fixed by #7204

Comments

@MurzNN
Copy link
Contributor

MurzNN commented Jan 17, 2022

  1. Start the examples/blog project, fill with some data.
  2. In onConnect function write two queries:
      console.log(await context.db.Post.findMany({ take: 1 }));
      console.log(await context.db.Author.findMany({ take: 1 }));
  1. See in console that in Author list item the posts relationship field is missing.
    But in Post the author relationship field is present.

Will be good to describe what rule does depend on this, seems it is simple like "only relationships with many = false"?
And what about update functions - can we fill relationships with many=true or not?

So please add this nuance to the documentation here https://keystonejs.com/docs/apis/db-items

And maybe there is some option exists to load item with many relationship fields?

@MurzNN MurzNN changed the title Missing some relationship fields in Database API find query results Missing relationship fields with many in Database API find query results Jan 17, 2022
@MurzNN
Copy link
Contributor Author

MurzNN commented Jan 17, 2022

In context.prisma we can require needed relationship fields individually via nested reads: https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#nested-reads

      const result = await context.prisma.author.findMany({
        take: 2,
        include: {
          posts: {
            select: {
              id: true,
            },
          },
        },
      });
      console.log(result[0]);

So maybe let expose this Prisma API to Database API too?

@MurzNN
Copy link
Contributor Author

MurzNN commented Jan 19, 2022

Together with adding include and select for relationship fields, we will also give the ability to query only specific fields from database like this:

      const result = await context.db.Author.findMany({
        take: 2,
        select: {
          name: true,
        },
        include: {
          posts: {
            select: {
              id: true,
            },
          },
        },
      });

@MurzNN
Copy link
Contributor Author

MurzNN commented Jan 19, 2022

Seems we can simply add include and select arguments to current findMany() and related functions here:

export async function findMany(
{ where, take, skip, orderBy: rawOrderBy }: FindManyArgsValue,

and pass them to runWithPrisma() directly, something like this: #7204
Is this right way to implement that?

@keystonejs keystonejs locked and limited conversation to collaborators Feb 28, 2022
@dcousens dcousens converted this issue into discussion #7313 Feb 28, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants