feat(graphql): add DateTime support instead of String

This commit is contained in:
Johann Pinson 2018-06-19 11:13:32 +02:00
parent dfca7d9580
commit 1d4a193f7e
2 changed files with 11 additions and 5 deletions

View File

@ -27,7 +27,8 @@
"graphql-depth-limit": "^1.1.0", "graphql-depth-limit": "^1.1.0",
"graphql-playground-middleware-koa": "^1.6.1", "graphql-playground-middleware-koa": "^1.6.1",
"graphql-tools": "^2.23.1", "graphql-tools": "^2.23.1",
"graphql-type-json": "^0.2.0", "graphql-type-json": "^0.2.1",
"graphql-type-datetime": "^0.2.1",
"pluralize": "^7.0.0", "pluralize": "^7.0.0",
"strapi-utils": "3.0.0-alpha.12.4" "strapi-utils": "3.0.0-alpha.12.4"
}, },

View File

@ -14,6 +14,7 @@ const pluralize = require('pluralize');
const graphql = require('graphql'); const graphql = require('graphql');
const { makeExecutableSchema } = require('graphql-tools'); const { makeExecutableSchema } = require('graphql-tools');
const GraphQLJSON = require('graphql-type-json'); const GraphQLJSON = require('graphql-type-json');
const GraphQLDateTime = require('graphql-type-datetime');
const policyUtils = require('strapi-utils').policy; const policyUtils = require('strapi-utils').policy;
module.exports = { module.exports = {
@ -170,6 +171,9 @@ module.exports = {
case 'float': case 'float':
type = 'Float'; type = 'Float';
break; break;
case 'date':
type = 'DateTime';
break;
case 'enumeration': case 'enumeration':
type = this.convertEnumType(definition, modelName, attributeName); type = this.convertEnumType(definition, modelName, attributeName);
break; break;
@ -453,8 +457,8 @@ module.exports = {
// Add timestamps attributes. // Add timestamps attributes.
if (_.get(model, 'options.timestamps') === true) { if (_.get(model, 'options.timestamps') === true) {
Object.assign(initialState, { Object.assign(initialState, {
createdAt: 'String!', createdAt: 'DateTime!',
updatedAt: 'String!' updatedAt: 'DateTime!'
}); });
Object.assign(acc.resolver[globalId], { Object.assign(acc.resolver[globalId], {
@ -777,10 +781,11 @@ module.exports = {
addCustomScalar: (resolvers) => { addCustomScalar: (resolvers) => {
Object.assign(resolvers, { Object.assign(resolvers, {
JSON: GraphQLJSON JSON: GraphQLJSON,
DateTime: GraphQLDateTime,
}); });
return 'scalar JSON'; return 'scalar JSON \n scalar DateTime';
}, },
/** /**