2021-08-24 17:56:44 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { get, difference } = require('lodash/fp');
|
|
|
|
|
|
|
|
module.exports = ({ strapi }) => {
|
2021-09-09 11:31:29 +02:00
|
|
|
const { STRAPI_SCALARS, SCALARS_ASSOCIATIONS } = strapi.plugin('graphql').service('constants');
|
2021-08-24 17:56:44 +02:00
|
|
|
|
2021-09-09 11:31:29 +02:00
|
|
|
const missingStrapiScalars = difference(STRAPI_SCALARS, Object.keys(SCALARS_ASSOCIATIONS));
|
2021-08-24 17:56:44 +02:00
|
|
|
|
|
|
|
if (missingStrapiScalars.length > 0) {
|
|
|
|
throw new Error('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) {
|
2021-09-09 11:31:29 +02:00
|
|
|
return get(strapiScalar, SCALARS_ASSOCIATIONS);
|
2021-08-24 17:56:44 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|