diff --git a/.gitignore b/.gitignore index c8c54e51..57696efe 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,6 @@ typings/ .serverless .webpack .cache-loader + +# JetBrains Settings +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index b773f630..d9a2a47d 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ And all this works without having to install Webpack, Babel, ESLint, etc. or man - "babel-eslint" - "babel-loader" - "eslint-loader" +- "graphql-tag/loader" - "@babel/runtime" - "@babel/preset-env" - "serverless-webpack" @@ -282,6 +283,14 @@ import "./assets/style.css"; import "./assets/style.scss"; import "./assets/react.png"; ``` +### gql, graphql Files + +Serverless Bundle automatically supports importing .gql, .graphql files. + +``` js +import "./modules/users.gql"; +import "./modules/messages.graphql"; +``` ### Externals vs forceExclude diff --git a/package-lock.json b/package-lock.json index e7ce302e..cb292f79 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4439,11 +4439,40 @@ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.0.tgz", "integrity": "sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==" }, + "graphql": { + "version": "15.2.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.2.0.tgz", + "integrity": "sha512-tsceRyHfgzZo+ee0YK3o8f0CR0cXAXxRlxoORWFo/CoM1bVy3UXGWeyzBcf+Y6oqPvO27BDmOEVATcunOO/MrQ==" + }, + "graphql-tag": { + "version": "2.10.3", + "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.10.3.tgz", + "integrity": "sha512-4FOv3ZKfA4WdOKJeHdz6B3F/vxBLSgmBcGeAFPf4n1F64ltJUvOOerNj0rsJxONQGdhUMynQIvd6LzB+1J5oKA==" + }, "growly": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz", "integrity": "sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=" }, + "handlebars": { + "version": "4.7.6", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.6.tgz", + "integrity": "sha512-1f2BACcBfiwAfStCKZNrUCgqNZkGsAT7UM3kkYtXuLo0KnaVfjKOyf7PRzB6++aK9STyT1Pd2ZCPe3EGOXleXA==", + "requires": { + "minimist": "^1.2.5", + "neo-async": "^2.6.0", + "source-map": "^0.6.1", + "uglify-js": "^3.1.4", + "wordwrap": "^1.0.0" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + } + } + }, "har-schema": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", @@ -5192,7 +5221,11 @@ }, "istanbul-reports": { "version": "2.2.6", - "resolved": "" + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-2.2.6.tgz", + "integrity": "sha512-SKi4rnMyLBKe0Jy2uUdx28h8oG7ph2PPuQPvIAh31d+Ci+lSiEu4C+h3oBPuJ9+mPKhOyW0M8gY4U5NM1WLeXA==", + "requires": { + "handlebars": "^4.1.2" + } }, "jest": { "version": "24.8.0", @@ -9933,6 +9966,12 @@ "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" }, + "uglify-js": { + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.10.0.tgz", + "integrity": "sha512-Esj5HG5WAyrLIdYU74Z3JdG2PxdIusvj6IWHMtlyESxc7kcDz7zYlYjpnSokn1UbpV0d/QX9fan7gkCNd/9BQA==", + "optional": true + }, "unicode-canonical-property-names-ecmascript": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz", diff --git a/package.json b/package.json index 37e32889..7af035de 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,8 @@ "eslint": "^5.16.0", "eslint-config-strongloop": "^2.1.0", "eslint-loader": "^2.2.1", + "graphql": "^15.2.0", + "graphql-tag": "^2.10.3", "hard-source-webpack-plugin": "^0.13.1", "ignore-loader": "^0.1.2", "isomorphic-style-loader": "^5.1.0", diff --git a/src/webpack.config.js b/src/webpack.config.js index 6d6a5c5f..0975ed35 100644 --- a/src/webpack.config.js +++ b/src/webpack.config.js @@ -114,7 +114,12 @@ function loaders() { "sass-loader" ] }, - { test: /\.gif|\.svg|\.png|\.jpg|\.jpeg$/, loader: "ignore-loader" } + { test: /\.gif|\.svg|\.png|\.jpg|\.jpeg$/, loader: "ignore-loader" }, + { + test: /\.(graphql|gql)$/, + exclude: /node_modules/, + loader: 'graphql-tag/loader' + } ] }; diff --git a/tests/graphql-loaders/.gitignore b/tests/graphql-loaders/.gitignore new file mode 100644 index 00000000..2b48c8bd --- /dev/null +++ b/tests/graphql-loaders/.gitignore @@ -0,0 +1,6 @@ +# package directories +node_modules +jspm_packages + +# Serverless directories +.serverless \ No newline at end of file diff --git a/tests/graphql-loaders/handler.js b/tests/graphql-loaders/handler.js new file mode 100644 index 00000000..dcba56d3 --- /dev/null +++ b/tests/graphql-loaders/handler.js @@ -0,0 +1,17 @@ +import Users from "./modules/users.gql"; +import Messages from "./modules/messages.graphql"; + +export const hello = async (event, context) => { + const statusCode = + typeof Users !== "undefined" && typeof Messages !== "undefined" ? 200 : 500; + return { + statusCode: statusCode, + body: JSON.stringify({ + message: + statusCode === 200 + ? "Go Serverless v1.0! Your function executed successfully!" + : "Error importing graphql", + input: event + }) + }; +}; diff --git a/tests/graphql-loaders/modules/messages.graphql b/tests/graphql-loaders/modules/messages.graphql new file mode 100644 index 00000000..36458a4c --- /dev/null +++ b/tests/graphql-loaders/modules/messages.graphql @@ -0,0 +1,9 @@ +type Messages { + user:ID! + messages:[Message] +} +type Message { + id:ID! + timestamp:String + message:String +} \ No newline at end of file diff --git a/tests/graphql-loaders/modules/users.gql b/tests/graphql-loaders/modules/users.gql new file mode 100644 index 00000000..b1986959 --- /dev/null +++ b/tests/graphql-loaders/modules/users.gql @@ -0,0 +1,5 @@ +type Users { + id:ID! + name:String + nickname:String +} \ No newline at end of file diff --git a/tests/graphql-loaders/package-lock.json b/tests/graphql-loaders/package-lock.json new file mode 100644 index 00000000..c0c042c0 --- /dev/null +++ b/tests/graphql-loaders/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "graphql-loader", + "version": "1.0.0", + "lockfileVersion": 1 +} diff --git a/tests/graphql-loaders/package.json b/tests/graphql-loaders/package.json new file mode 100644 index 00000000..07f28a0a --- /dev/null +++ b/tests/graphql-loaders/package.json @@ -0,0 +1,12 @@ +{ + "name": "graphql-loader", + "version": "1.0.0", + "description": "", + "main": "handler.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/tests/graphql-loaders/serverless.yml b/tests/graphql-loaders/serverless.yml new file mode 100644 index 00000000..7213fbd0 --- /dev/null +++ b/tests/graphql-loaders/serverless.yml @@ -0,0 +1,12 @@ +service: my-service + +plugins: + - '../../index' + +provider: + name: aws + runtime: nodejs10.x + +functions: + hello: + handler: handler.hello diff --git a/tests/index.test.js b/tests/index.test.js index aef1a7ed..4449438f 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -117,6 +117,11 @@ test("isomorphic loaders", () => { expect(results).not.toMatch(errorRegex); }); +test("graphql loaders", () => { + const results = runSlsCommand("graphql-loaders"); + expect(results).not.toMatch(errorRegex); +}); + function clearNodeModules(cwd) { const { stdout, error } = spawnSync("rm", ["-rf", "node_modules/"], { cwd,