strapi/packages/plugins/graphql/server/services/utils/mappers/strapi-scalar-to-graphql-scalar.js

26 lines
791 B
JavaScript
Raw Normal View History

'use strict';
const { get, difference } = require('lodash/fp');
2021-10-27 18:54:58 +02:00
const { ApplicationError } = require('@strapi/utils').errors;
module.exports = ({ strapi }) => {
const { STRAPI_SCALARS, SCALARS_ASSOCIATIONS } = strapi.plugin('graphql').service('constants');
const missingStrapiScalars = difference(STRAPI_SCALARS, Object.keys(SCALARS_ASSOCIATIONS));
if (missingStrapiScalars.length > 0) {
2021-10-27 18:54:58 +02:00
throw new ApplicationError('Some Strapi scalars are not handled in the GraphQL scalars mapper');
}
return {
/**
* Used to transform a Strapi scalar type into its GraphQL equivalent
* @param {string} strapiScalar
* @return {NexusGenScalars}
*/
strapiScalarToGraphQLScalar(strapiScalar) {
return get(strapiScalar, SCALARS_ASSOCIATIONS);
},
};
};