enables pagination on nested relationship gql queries

This commit is contained in:
James
2020-04-10 11:25:39 -04:00
parent 2b39c449d8
commit 7b6d24669b

View File

@@ -4,6 +4,7 @@
const {
GraphQLString,
GraphQLFloat,
GraphQLInt,
GraphQLBoolean,
GraphQLList,
GraphQLObjectType,
@@ -150,7 +151,7 @@ function getBuildObjectType(graphQLContext) {
if (id) {
id = id.toString();
const relatedDocument = await find({
const relatedDocumentQuery = {
model: graphQLContext.collections[relatedCollectionSlug].model,
query: {
where: {
@@ -160,9 +161,15 @@ function getBuildObjectType(graphQLContext) {
},
},
},
paginate: {},
locale,
fallbackLocale,
});
};
if (args.page) relatedDocumentQuery.paginate.page = args.page;
if (args.limit) relatedDocumentQuery.paginate.limit = args.limit;
const relatedDocument = await find();
if (relatedDocument.docs[0]) return relatedDocument.docs[0];
@@ -173,6 +180,11 @@ function getBuildObjectType(graphQLContext) {
},
};
if (hasManyValues) {
relationship.args.page = { type: GraphQLInt };
relationship.args.limit = { type: GraphQLInt };
}
if (isRelatedToManyCollections) {
const relatedCollectionFields = relationTo.reduce((allFields, relation) => {
return [