question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Include in FindManyXArgs

See original GitHub issue

Hi,

I was wondering if there’s a way to add the include argument in the FindManyXArgs.

Something like the one prisma autogenerates

image

Currenty this is what it generates

@ArgsType()
export class FindManyUserArgs {
    @Field(() => UserWhereInput, {nullable:true})
    where?: UserWhereInput;

    @Field(() => [UserOrderByWithRelationInput], {nullable:true})
    orderBy?: Array<UserOrderByWithRelationInput>;

    @Field(() => UserWhereUniqueInput, {nullable:true})
    cursor?: UserWhereUniqueInput;

    @Field(() => Int, {nullable:true})
    take?: number;

    @Field(() => Int, {nullable:true})
    skip?: number;

    @Field(() => [UserScalarFieldEnum], {nullable:true})
    distinct?: Array<keyof typeof UserScalarFieldEnum>;
}

I’d need something like this

@ArgsType()
export class FindManyUserArgs {
    ...
    
   @Field(() => UserIncludeInput, { nullable: true })
   include?: UserIncludeInput;
}

The reason is because I need to run queries like this

image

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hotrungnhancommented, Nov 20, 2022

The problem is that this.prisma.user.findMany({ include { posts: true } }) selects ALL columns from posts table, but graphql server will send to client only name. You should use select

this.prisma.user.findMany({ select: { id: true, name: true, posts: { select: { name: true }} } })

{ select: { id: true, name: true, posts: { select: { name: true }} } } this object can be created from GraphQLResolveInfo

    @Query(() => [User])
    async users(
		@Args() args: FindManyUserArgs,
        @Info() info: GraphQLResolveInfo,
    ) {
        const select = createUserSelectFromInfo(info);
        return await prisma.user.findMany({ ...args, select });
    }

See https://docs.nestjs.com/graphql/resolvers#graphql-argument-decorators

why didn’t put a doccument on this ?

1reaction
unlightcommented, Sep 22, 2021

There is no such options for generator. But I think ‘select’ is more suitable for this case. You can reinvent the wheel and create your own fields parser, similar to https://github.com/Robert-W/graphql-outfields and use result in ‘select’ property of ‘findMany’ method.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I pass all arguments with xargs in middle of ...
I want to pass all the files as a single argument on Linux but I am not able to do that. This is...
Read more >
How to Use the Linux xargs Command - phoenixNAP
The xargs command builds and executes commands provided through the standard input. Learn how to use it with practical examples.
Read more >
xargs(1) - Linux manual page - man7.org
xargs - build and execute command lines from standard input ... Because Unix filenames can contain blanks and newlines, this default behaviour is...
Read more >
findutils: ChangeLog - 4.6.0 vs. 4.7.0 changes | Fossies Diffs
Source code changes report for the member file ChangeLog of the findutils software package between the versions 4.6.0 and 4.7.0.
Read more >
xargs - Construct an argument list and run a command - IBM
-n number: Specifies xargs is to read the given number of arguments from the standard input and put them on the end of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found