2021-07-05 10:43:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { objectType } = require('nexus');
|
2021-09-01 12:06:51 +02:00
|
|
|
const { prop, identity } = 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');
|
|
|
|
|
|
|
|
return {
|
|
|
|
/**
|
2021-09-07 11:23:49 +02:00
|
|
|
* Build a higher level type for a content type which contains the attributes, the ID and the metadata
|
2021-08-24 17:56:44 +02:00
|
|
|
* @param {object} contentType The content type which will be used to build its entity type
|
|
|
|
* @return {NexusObjectTypeDef}
|
|
|
|
*/
|
|
|
|
buildEntityDefinition(contentType) {
|
|
|
|
const name = naming.getEntityName(contentType);
|
|
|
|
const typeName = naming.getTypeName(contentType);
|
|
|
|
|
|
|
|
return objectType({
|
|
|
|
name,
|
|
|
|
|
|
|
|
definition(t) {
|
|
|
|
// Keep the ID attribute at the top level
|
|
|
|
t.id('id', { resolve: prop('id') });
|
|
|
|
|
|
|
|
// Keep the fetched object into a dedicated `attributes` field
|
|
|
|
t.field('attributes', {
|
|
|
|
type: typeName,
|
2021-09-01 12:06:51 +02:00
|
|
|
resolve: identity,
|
2021-08-24 17:56:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// todo[v4]: add the meta field to the entity when there will be data in it (can't add an empty type for now)
|
|
|
|
// t.field('meta', { type: utils.getEntityMetaName(contentType) });
|
|
|
|
},
|
2021-07-30 11:44:26 +02:00
|
|
|
});
|
2021-07-05 10:43:36 +02:00
|
|
|
},
|
2021-08-24 17:56:44 +02:00
|
|
|
};
|
2021-07-05 10:43:36 +02:00
|
|
|
};
|