diff --git a/packages/strapi-plugin-graphql/package.json b/packages/strapi-plugin-graphql/package.json index b048fa98e2..c8e35cade1 100644 --- a/packages/strapi-plugin-graphql/package.json +++ b/packages/strapi-plugin-graphql/package.json @@ -27,7 +27,8 @@ "graphql-depth-limit": "^1.1.0", "graphql-playground-middleware-koa": "^1.6.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", "strapi-utils": "3.0.0-alpha.12.4" }, diff --git a/packages/strapi-plugin-graphql/services/GraphQL.js b/packages/strapi-plugin-graphql/services/GraphQL.js index 0e43ea9674..c345637d1e 100644 --- a/packages/strapi-plugin-graphql/services/GraphQL.js +++ b/packages/strapi-plugin-graphql/services/GraphQL.js @@ -14,6 +14,7 @@ const pluralize = require('pluralize'); const graphql = require('graphql'); const { makeExecutableSchema } = require('graphql-tools'); const GraphQLJSON = require('graphql-type-json'); +const GraphQLDateTime = require('graphql-type-datetime'); const policyUtils = require('strapi-utils').policy; module.exports = { @@ -170,6 +171,9 @@ module.exports = { case 'float': type = 'Float'; break; + case 'date': + type = 'DateTime'; + break; case 'enumeration': type = this.convertEnumType(definition, modelName, attributeName); break; @@ -453,8 +457,8 @@ module.exports = { // Add timestamps attributes. if (_.get(model, 'options.timestamps') === true) { Object.assign(initialState, { - createdAt: 'String!', - updatedAt: 'String!' + createdAt: 'DateTime!', + updatedAt: 'DateTime!' }); Object.assign(acc.resolver[globalId], { @@ -777,10 +781,11 @@ module.exports = { addCustomScalar: (resolvers) => { Object.assign(resolvers, { - JSON: GraphQLJSON + JSON: GraphQLJSON, + DateTime: GraphQLDateTime, }); - return 'scalar JSON'; + return 'scalar JSON \n scalar DateTime'; }, /**