2021-07-05 10:43:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { objectType, nonNull } = require('nexus');
|
2021-08-18 14:56:46 +02:00
|
|
|
const { defaultTo, prop, pipe } = require('lodash/fp');
|
2021-07-05 10:43:36 +02:00
|
|
|
|
2021-08-24 17:56:44 +02:00
|
|
|
module.exports = ({ strapi }) => {
|
|
|
|
const { naming } = strapi.plugin('graphql').service('utils');
|
|
|
|
const { RESPONSE_COLLECTION_META_TYPE_NAME } = strapi.plugin('graphql').service('constants');
|
2021-07-05 10:43:36 +02:00
|
|
|
|
2021-08-24 17:56:44 +02:00
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* Build a type definition for a content API collection response for a given content type
|
|
|
|
* @param {object} contentType The content type which will be used to build its content API response definition
|
|
|
|
* @return {NexusObjectTypeDef}
|
|
|
|
*/
|
2021-09-23 14:26:31 +02:00
|
|
|
buildResponseCollectionDefinition(contentType) {
|
2021-08-24 17:56:44 +02:00
|
|
|
const name = naming.getEntityResponseCollectionName(contentType);
|
|
|
|
const entityName = naming.getEntityName(contentType);
|
2021-07-05 10:43:36 +02:00
|
|
|
|
2021-08-24 17:56:44 +02:00
|
|
|
return objectType({
|
|
|
|
name,
|
2021-07-05 10:43:36 +02:00
|
|
|
|
2021-08-24 17:56:44 +02:00
|
|
|
definition(t) {
|
|
|
|
t.nonNull.list.field('data', {
|
|
|
|
type: nonNull(entityName),
|
2021-07-05 10:43:36 +02:00
|
|
|
|
2021-08-24 17:56:44 +02:00
|
|
|
resolve: pipe(prop('nodes'), defaultTo([])),
|
|
|
|
});
|
2021-07-30 11:44:26 +02:00
|
|
|
|
2021-08-24 17:56:44 +02:00
|
|
|
t.nonNull.field('meta', {
|
|
|
|
type: RESPONSE_COLLECTION_META_TYPE_NAME,
|
2021-09-01 12:06:51 +02:00
|
|
|
|
2021-08-24 17:56:44 +02:00
|
|
|
// Pass down the args stored in the source object
|
|
|
|
resolve: prop('info'),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|