{"version":3,"file":"entity.mjs","sources":["../../../../server/src/services/builders/entity.ts"],"sourcesContent":["import { objectType } from 'nexus';\nimport { prop, identity, isEmpty } from 'lodash/fp';\nimport type { Schema } from '@strapi/types';\n\nimport type { Context } from '../types';\n\nexport default ({ strapi }: Context) => {\n  const { naming } = strapi.plugin('graphql').service('utils');\n\n  return {\n    /**\n     * Build a higher level type for a content type which contains the attributes, the ID and the metadata\n     * @param {object} contentType The content type which will be used to build its entity type\n     * @return {NexusObjectTypeDef}\n     */\n    buildEntityDefinition(contentType: Schema.ContentType) {\n      const { attributes } = contentType;\n\n      const name = naming.getEntityName(contentType);\n      const typeName = naming.getTypeName(contentType);\n\n      return objectType({\n        name,\n\n        definition(t) {\n          // Keep the ID attribute at the top level\n          t.id('id', { resolve: prop('id') });\n\n          if (!isEmpty(attributes)) {\n            // Keep the fetched object into a dedicated `attributes` field\n            t.field('attributes', {\n              type: typeName,\n              resolve: identity,\n            });\n          }\n        },\n      });\n    },\n  };\n};\n"],"names":["strapi","naming","plugin","service","buildEntityDefinition","contentType","attributes","name","getEntityName","typeName","getTypeName","objectType","definition","t","id","resolve","prop","isEmpty","field","type","identity"],"mappings":";;;AAMA,aAAe,CAAA,CAAC,EAAEA,MAAM,EAAW,GAAA;IACjC,MAAM,EAAEC,MAAM,EAAE,GAAGD,OAAOE,MAAM,CAAC,SAAWC,CAAAA,CAAAA,OAAO,CAAC,OAAA,CAAA;IAEpD,OAAO;AACL;;;;AAIC,QACDC,uBAAsBC,WAA+B,EAAA;YACnD,MAAM,EAAEC,UAAU,EAAE,GAAGD,WAAAA;YAEvB,MAAME,IAAAA,GAAON,MAAOO,CAAAA,aAAa,CAACH,WAAAA,CAAAA;YAClC,MAAMI,QAAAA,GAAWR,MAAOS,CAAAA,WAAW,CAACL,WAAAA,CAAAA;AAEpC,YAAA,OAAOM,UAAW,CAAA;AAChBJ,gBAAAA,IAAAA;AAEAK,gBAAAA,UAAAA,CAAAA,CAAWC,CAAC,EAAA;;oBAEVA,CAAEC,CAAAA,EAAE,CAAC,IAAM,EAAA;AAAEC,wBAAAA,OAAAA,EAASC,IAAK,CAAA,IAAA;AAAM,qBAAA,CAAA;oBAEjC,IAAI,CAACC,QAAQX,UAAa,CAAA,EAAA;;wBAExBO,CAAEK,CAAAA,KAAK,CAAC,YAAc,EAAA;4BACpBC,IAAMV,EAAAA,QAAAA;4BACNM,OAASK,EAAAA;AACX,yBAAA,CAAA;AACF;AACF;AACF,aAAA,CAAA;AACF;AACF,KAAA;AACF,CAAA;;;;"}