wemaintain / auto-relay

Relay made simple in code-first GraphQL typescript applications
Apache License 2.0
73 stars 6 forks source link

Auto-relay not working with nest's typegraphql implementation #23

Open dan-klasson opened 4 years ago

dan-klasson commented 4 years ago

According to the documentation this library has two goals:

I'm trying to just implement pagination on my user model without any relationships. Is that even possible? This is what I've tried:

@Resolver(of => UserModel)
export class User {
    constructor(
        @InjectRepository(UserModel)
        private readonly userRepository: Repository<UserModel>,
    ) {
    }

    @RelayedQuery(() => UserModel)
    async users(
        @RelayLimitOffset() {limit, offset}: RelayLimitOffsetArgs
    ): Promise<[UserModel[], number]> {
        return this.userRepository.findAndCount({ 
            skip: offset,
            take: limit
        })
    }

And the stacktrace I'm getting:

"Error: Cannot return null for non-nullable field Query.users.",
"    at completeValue (/Users/danklasson/Code/analyze-jestsj/node_modules/graphql/execution/execute.js:560:13)",
"    at completeValueCatchingError (/Users/danklasson/Code/analyze-jestsj/node_modules/graphql/execution/execute.js:495:19)",
"    at resolveField (/Users/danklasson/Code/analyze-jestsj/node_modules/graphql/execution/execute.js:435:10)",
"    at executeFields (/Users/danklasson/Code/analyze-jestsj/node_modules/graphql/execution/execute.js:275:18)",
"    at executeOperation (/Users/danklasson/Code/analyze-jestsj/node_modules/graphql/execution/execute.js:219:122)",
"    at executeImpl (/Users/danklasson/Code/analyze-jestsj/node_modules/graphql/execution/execute.js:104:14)",
"    at Object.execute (/Users/danklasson/Code/analyze-jestsj/node_modules/graphql/execution/execute.js:64:35)",
"    at /Users/danklasson/Code/analyze-jestsj/node_modules/apollo-server-core/dist/requestPipeline.js:246:46",
"    at Generator.next (<anonymous>)",
"    at /Users/danklasson/Code/analyze-jestsj/node_modules/apollo-server-core/dist/requestPipeline.js:8:71"

It's taken straight from the documentation. But I had to switch the order of the type declaration of the return Promise to get it to compile. What am I missing here?

Superd22 commented 4 years ago

Hello,

Yes it is entirely possible. To answer both your questions : 1/ the orders of the type declaration changed with #20, I forgot to update the docs to reflect that, mea culpa. 2/ The provided example should indeed work and is a usecase we have internally. Could you link to a minimal repro repo ?

dan-klasson commented 4 years ago

@Superd22 Here's a minimal reproducible repo:

https://github.com/dan-klasson/project-autorelay

Run npm i, npm run-script build and npm start.

Superd22 commented 4 years ago

Hey @dan-klasson thanks for taking the time to make a repro repo. It seems to be an issue with using nests js' integration with typegraphql rather than vanilla.

I'll look into it further

kodeine commented 4 years ago

hello, was this fixed?

Superd22 commented 4 years ago

I'll try and have a look at this in the next few days :)

dan-klasson commented 4 years ago

@Superd22 Did you get a chance to look at this? Do you have any pointers you can share?

dzcpy commented 2 years ago

Any updates?

dan-klasson commented 2 years ago

@kodeine and @dzcpy

just use this: https://github.com/doug-martin/nestjs-query

dzcpy commented 2 years ago

@dan-klasson Thanks for your reply, nestjs-query seems good. But it doesn't have a mikro-orm adapter which is what I'm currently using..