/
githubmirror
/
strapi
Обзор
Документация
Войти
/
githubmirror
/
strapi
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/plugins/graphql/server/src/services/builders/generic-morph.ts
41 строка
1 KB
Alexandre BODIN
chore(graphql): migration to basic ts (#18696)
08 ноя 2023, 20:21
Не верифицирован
08 ноя 2023, 20:21
5c5ae94
Код
Авторство
О чём код?
import { unionType } from 'nexus'; import { prop } from 'lodash/fp'; import type { Context } from '../types'; export default ({ strapi, registry }: Context) => { const { naming } = strapi.plugin('graphql').service('utils'); const { KINDS, GENERIC_MORPH_TYPENAME } = strapi.plugin('graphql').service('constants'); return { buildGenericMorphDefinition() { return unionType({ name: GENERIC_MORPH_TYPENAME, resolveType(obj: any) { const contentType = strapi.getModel(obj.__type); if (!contentType) { return null; } if (contentType.modelType === 'component') { return naming.getComponentName(contentType); } return naming.getTypeName(contentType); }, definition(t: any) { const members = registry // Resolve every content-type or component .where(({ config }) => [KINDS.type, KINDS.component].includes(config.kind)) // Only keep their name (the type's id) .map(prop('name')); t.members(...members); }, }); }, }; };