prismake / typegql

Create GraphQL schema with TypeScript classes.
https://prismake.github.io/typegql/
MIT License
423 stars 21 forks source link

Pagination Count in Query #65

Closed mkuczera closed 5 years ago

mkuczera commented 5 years ago

Hey, do you have any recommendations to enable a Pagination as a result field? I ran into some issues adding a return field to the Query type.

@Query({type: [Listing]})
    async getAllListings(latitudeFrom: number, latitudeTo: number, longitudeFrom: number, longitudeTo: number, page: number, limit: number): Promise<{result: Listing[], total_count: number}> {
        const [results, count] = await Listing.findAndCount({
            where: { 
                latitude: Between(latitudeFrom, latitudeTo),
                longitude: Between(longitudeFrom, longitudeTo)
            },
            cache: false,
            take: limit,
            skip: (page - 1) * limit
        });

        return {
            result: results,
            total_count: count
        };
    }

This code is resulting in the error message "Expected Iterable, but did not find one for field Query.getAllListings."

The problem is maybe on the way to understand what i can pass as a type to the Query element. Is there any kind of documentation how to resolve this issue?

Greetings Michael

pie6k commented 5 years ago

As you've closed it I assume you were able to resolve your issue.

If possible, you can share your approach - maybe it'll be useful for someone.