2021-07-05 10:43:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { objectType } = require('nexus');
|
2021-07-30 11:44:26 +02:00
|
|
|
const { prop } = require('lodash/fp');
|
2021-07-05 10:43:36 +02:00
|
|
|
|
2021-08-24 12:10:47 +02:00
|
|
|
const { utils } = require('../types');
|
2021-07-05 10:43:36 +02:00
|
|
|
|
2021-07-30 11:44:26 +02:00
|
|
|
module.exports = () => ({
|
|
|
|
/**
|
|
|
|
* Build a type definition for a content API 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}
|
|
|
|
*/
|
|
|
|
buildResponseDefinition: contentType => {
|
|
|
|
const name = utils.getEntityResponseName(contentType);
|
|
|
|
const entityName = utils.getEntityName(contentType);
|
2021-07-05 10:43:36 +02:00
|
|
|
|
2021-07-30 11:44:26 +02:00
|
|
|
return objectType({
|
|
|
|
name,
|
2021-07-05 10:43:36 +02:00
|
|
|
|
2021-07-30 11:44:26 +02:00
|
|
|
definition(t) {
|
|
|
|
t.field('data', {
|
|
|
|
type: entityName,
|
2021-07-05 10:43:36 +02:00
|
|
|
|
2021-07-30 11:44:26 +02:00
|
|
|
resolve: prop('value'),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2021-07-05 10:43:36 +02:00
|
|
|
});
|