diff --git a/packages/strapi-plugin-graphql/package.json b/packages/strapi-plugin-graphql/package.json index 9b4f503449..25f6cbc396 100644 --- a/packages/strapi-plugin-graphql/package.json +++ b/packages/strapi-plugin-graphql/package.json @@ -16,9 +16,9 @@ "glob": "^7.1.4", "graphql": "^14.3.0", "graphql-depth-limit": "^1.1.0", + "graphql-iso-date": "^3.6.1", "graphql-playground-middleware-koa": "^1.6.0", "graphql-tools": "4.0.6", - "graphql-type-datetime": "^0.2.4", "graphql-type-json": "0.3.1", "graphql-type-long": "^0.1.1", "koa-compose": "^4.1.0", diff --git a/packages/strapi-plugin-graphql/services/Mutation.js b/packages/strapi-plugin-graphql/services/Mutation.js index ac1af5aee8..d2cff29993 100644 --- a/packages/strapi-plugin-graphql/services/Mutation.js +++ b/packages/strapi-plugin-graphql/services/Mutation.js @@ -214,7 +214,7 @@ module.exports = { // Resolver can be a function. Be also a native resolver or a controller's action. if (_.isFunction(resolver)) { - const normalizedName = _.toLower(name); + const normalizedName = _.camelCase(name); if (isController) { const values = await resolver.call(null, context); diff --git a/packages/strapi-plugin-graphql/services/Types.js b/packages/strapi-plugin-graphql/services/Types.js index 5bc612bcfd..d3da87d831 100644 --- a/packages/strapi-plugin-graphql/services/Types.js +++ b/packages/strapi-plugin-graphql/services/Types.js @@ -10,7 +10,8 @@ const _ = require('lodash'); const { GraphQLUpload } = require('apollo-server-koa'); const graphql = require('graphql'); const { GraphQLJSON } = require('graphql-type-json'); -const GraphQLDateTime = require('graphql-type-datetime'); +const { GraphQLDate, GraphQLDateTime } = require('graphql-iso-date'); +const Time = require('../types/time'); const GraphQLLong = require('graphql-type-long'); const { toSingular } = require('./naming'); @@ -60,8 +61,12 @@ module.exports = { case 'json': type = 'JSON'; break; - case 'time': case 'date': + type = 'Date'; + break; + case 'time': + type = 'Time'; + break; case 'datetime': case 'timestamp': type = 'DateTime'; @@ -180,14 +185,20 @@ module.exports = { */ addCustomScalar(resolvers) { - Object.assign(resolvers, { + const scalars = { JSON: GraphQLJSON, DateTime: GraphQLDateTime, + Time, + Date: GraphQLDate, Long: GraphQLLong, Upload: GraphQLUpload, - }); + }; - return 'scalar JSON \n scalar DateTime \n scalar Long \n scalar Upload'; + Object.assign(resolvers, scalars); + + return Object.keys(scalars) + .map(key => `scalar ${key}`) + .join('\n'); }, /** diff --git a/packages/strapi-plugin-graphql/types/time.js b/packages/strapi-plugin-graphql/types/time.js new file mode 100644 index 0000000000..42bae73883 --- /dev/null +++ b/packages/strapi-plugin-graphql/types/time.js @@ -0,0 +1,26 @@ +'use strict'; + +const { parseType } = require('strapi-utils'); + +const { Kind, GraphQLScalarType } = require('graphql'); + +const Time = new GraphQLScalarType({ + name: 'Time', + description: 'A time string with format: HH:mm:ss.SSS', + serialize(value) { + return parseType({ type: 'time', value }); + }, + parseValue(value) { + return parseType({ type: 'time', value }); + }, + parseLiteral(ast) { + if (ast.kind !== Kind.STRING) { + throw new TypeError(`Time cannot represent non string type`); + } + + const value = ast.value; + return parseType({ type: 'time', value }); + }, +}); + +module.exports = Time; diff --git a/yarn.lock b/yarn.lock index 86dfb7fdbe..0b25163dcb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4685,7 +4685,7 @@ check-more-types@2.24.0: resolved "https://registry.yarnpkg.com/check-more-types/-/check-more-types-2.24.0.tgz#1420ffb10fd444dcfc79b43891bbfffd32a84600" integrity sha1-FCD/sQ/URNz8ebQ4kbv//TKoRgA= -cheerio@^1.0.0-rc.2: +cheerio@^1.0.0-rc.2, cheerio@^1.0.0-rc.3: version "1.0.0-rc.3" resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-1.0.0-rc.3.tgz#094636d425b2e9c0f4eb91a46c05630c9a1a8bf6" integrity sha512-0td5ijfUPuubwLUu0OBoe98gZj8C/AA+RW3v67GPlGOrvxWjZmBXiBCRU+I8VEiNyJzjth40POfHiz2RB3gImA== @@ -8513,6 +8513,11 @@ graphql-extensions@^0.10.7: apollo-server-env "^2.4.3" apollo-server-types "^0.2.8" +graphql-iso-date@^3.6.1: + version "3.6.1" + resolved "https://registry.yarnpkg.com/graphql-iso-date/-/graphql-iso-date-3.6.1.tgz#bd2d0dc886e0f954cbbbc496bbf1d480b57ffa96" + integrity sha512-AwFGIuYMJQXOEAgRlJlFL4H1ncFM8n8XmoVDTNypNOZyQ8LFDG2ppMFlsS862BSTCDcSUfHp8PD3/uJhv7t59Q== + graphql-playground-html@1.6.13: version "1.6.13" resolved "https://registry.yarnpkg.com/graphql-playground-html/-/graphql-playground-html-1.6.13.tgz#16d61416161d96f2725bc37b0b64d135a189f252" @@ -8559,13 +8564,6 @@ graphql-tools@^4.0.0: iterall "^1.1.3" uuid "^3.1.0" -graphql-type-datetime@^0.2.4: - version "0.2.4" - resolved "https://registry.yarnpkg.com/graphql-type-datetime/-/graphql-type-datetime-0.2.4.tgz#438cd3886ad2c7898af057ee3c4a5666bd153095" - integrity sha512-R/4Y7L+7WtBfW3g2WGv4NcU+hSPPES4JsiDzLl8sj30hEDxQyIwvJ2yJi8DGcBE8s325B6Q4ky5qwicZ7F0b7A== - dependencies: - moment "^2.22.2" - graphql-type-json@0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/graphql-type-json/-/graphql-type-json-0.3.1.tgz#47fca2b1fa7adc0758d165b33580d7be7a6cf548" @@ -12259,7 +12257,7 @@ moment@2.22.2: resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66" integrity sha1-PCV/mDn8DpP/UxSWMiOeuQeD/2Y= -"moment@>= 2.9.0", moment@>=1.6.0, moment@^2.16.0, moment@^2.22.2, moment@^2.24.0: +"moment@>= 2.9.0", moment@>=1.6.0, moment@^2.16.0, moment@^2.24.0: version "2.24.0" resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b" integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg== @@ -13630,10 +13628,10 @@ path-to-regexp@^1.1.1, path-to-regexp@^1.7.0: dependencies: isarray "0.0.1" -path-to-regexp@^3.0.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-3.1.0.tgz#f45a9cc4dc6331ae8f131e0ce4fde8607f802367" - integrity sha512-PtHLisEvUOepjc+sStXxJ/pDV/s5UBTOKWJY2SOz3e6E/iN/jLknY9WL72kTwRrwXDUbZTEAtSnJbz2fF127DA== +path-to-regexp@^3.1.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-3.2.0.tgz#fa7877ecbc495c601907562222453c43cc204a5f" + integrity sha512-jczvQbCUS7XmS7o+y1aEO9OBVFeZBQ1MDSEqmO7xSoPgOPoowY/SxLpZ6Vh97/8qHZOteiCKb7gkG9gA2ZUxJA== path-type@^1.0.0: version "1.1.0" @@ -17467,10 +17465,10 @@ svgo@^1.0.0, svgo@^1.0.5: unquote "~1.1.1" util.promisify "~1.0.0" -swagger-ui-dist@3.22.1: - version "3.22.1" - resolved "https://registry.yarnpkg.com/swagger-ui-dist/-/swagger-ui-dist-3.22.1.tgz#a7a4ebc5af5d28f7c9e1436be9a9258f5d23497e" - integrity sha512-KITbEqXkXrjGH12A0lpVZlH3uODFkwUh8d15My1YD4N0PSZDnIiC1iMFT6ryyuJxDYWZh0qezKpPqa5FRowngw== +swagger-ui-dist@3.24.3: + version "3.24.3" + resolved "https://registry.yarnpkg.com/swagger-ui-dist/-/swagger-ui-dist-3.24.3.tgz#99754d11b0ddd314a1a50db850acb415e4b0a0c6" + integrity sha512-kB8qobP42Xazaym7sD9g5mZuRL4416VIIYZMqPEIskkzKqbPLQGEiHA3ga31bdzyzFLgr6Z797+6X1Am6zYpbg== switchback@^2.0.1: version "2.0.5"