mirror of
https://github.com/strapi/strapi.git
synced 2025-07-27 10:56:36 +00:00
40 lines
946 B
JavaScript
40 lines
946 B
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
const { get, difference } = require('lodash/fp');
|
||
|
|
||
|
const associations = {
|
||
|
boolean: 'Boolean',
|
||
|
integer: 'Int',
|
||
|
string: 'String',
|
||
|
richtext: 'String',
|
||
|
biginteger: 'Long',
|
||
|
float: 'Float',
|
||
|
decimal: 'Float',
|
||
|
json: 'JSON',
|
||
|
date: 'Date',
|
||
|
time: 'Time',
|
||
|
datetime: 'DateTime',
|
||
|
timestamp: 'DateTime',
|
||
|
};
|
||
|
|
||
|
module.exports = ({ strapi }) => {
|
||
|
const { STRAPI_SCALARS } = strapi.plugin('graphql').service('constants');
|
||
|
|
||
|
const missingStrapiScalars = difference(STRAPI_SCALARS, Object.keys(associations));
|
||
|
|
||
|
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) {
|
||
|
return get(strapiScalar, associations);
|
||
|
},
|
||
|
};
|
||
|
};
|