diff --git a/package-lock.json b/package-lock.json index da47b71..a2cf049 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,6 +30,14 @@ "integrity": "sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==", "dev": true }, + "@wry/equality": { + "version": "0.1.9", + "resolved": "https://registry.npmjs.org/@wry/equality/-/equality-0.1.9.tgz", + "integrity": "sha512-mB6ceGjpMGz1ZTza8HYnrPGos2mC6So4NhS1PtZ8s4Qt0K7fBiIGhpSxUbQmhwcSWE3no+bYxmI2OL6KuXYmoQ==", + "requires": { + "tslib": "^1.9.3" + } + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -151,6 +159,48 @@ } } }, + "apollo-link": { + "version": "1.2.13", + "resolved": "https://registry.npmjs.org/apollo-link/-/apollo-link-1.2.13.tgz", + "integrity": "sha512-+iBMcYeevMm1JpYgwDEIDt/y0BB7VWyvlm/7x+TIPNLHCTCMgcEgDuW5kH86iQZWo0I7mNwQiTOz+/3ShPFmBw==", + "requires": { + "apollo-utilities": "^1.3.0", + "ts-invariant": "^0.4.0", + "tslib": "^1.9.3", + "zen-observable-ts": "^0.8.20" + } + }, + "apollo-link-http": { + "version": "1.5.16", + "resolved": "https://registry.npmjs.org/apollo-link-http/-/apollo-link-http-1.5.16.tgz", + "integrity": "sha512-IA3xA/OcrOzINRZEECI6IdhRp/Twom5X5L9jMehfzEo2AXdeRwAMlH5LuvTZHgKD8V1MBnXdM6YXawXkTDSmJw==", + "requires": { + "apollo-link": "^1.2.13", + "apollo-link-http-common": "^0.2.15", + "tslib": "^1.9.3" + } + }, + "apollo-link-http-common": { + "version": "0.2.15", + "resolved": "https://registry.npmjs.org/apollo-link-http-common/-/apollo-link-http-common-0.2.15.tgz", + "integrity": "sha512-+Heey4S2IPsPyTf8Ag3PugUupASJMW894iVps6hXbvwtg1aHSNMXUYO5VG7iRHkPzqpuzT4HMBanCTXPjtGzxg==", + "requires": { + "apollo-link": "^1.2.13", + "ts-invariant": "^0.4.0", + "tslib": "^1.9.3" + } + }, + "apollo-utilities": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/apollo-utilities/-/apollo-utilities-1.3.2.tgz", + "integrity": "sha512-JWNHj8XChz7S4OZghV6yc9FNnzEXj285QYp/nLNh943iObycI5GTDO3NGR9Dth12LRrSFMeDOConPfPln+WGfg==", + "requires": { + "@wry/equality": "^0.1.2", + "fast-json-stable-stringify": "^2.0.0", + "ts-invariant": "^0.4.0", + "tslib": "^1.9.3" + } + }, "aproba": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", @@ -909,6 +959,11 @@ "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" }, + "deprecated-decorator": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/deprecated-decorator/-/deprecated-decorator-0.1.6.tgz", + "integrity": "sha1-AJZjF7ehL+kvPMgx91g68ym4bDc=" + }, "destroy": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", @@ -1562,8 +1617,7 @@ "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", - "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", - "dev": true + "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" }, "fast-levenshtein": { "version": "2.0.6", @@ -1781,7 +1835,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -1802,12 +1857,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1822,17 +1879,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -1949,7 +2009,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -1961,6 +2022,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -1975,6 +2037,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -1982,12 +2045,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2006,6 +2071,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2086,7 +2152,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -2098,6 +2165,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2183,7 +2251,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -2219,6 +2288,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2238,6 +2308,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2281,12 +2352,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -2442,6 +2515,18 @@ "iterall": "^1.2.2" } }, + "graphql-tools": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/graphql-tools/-/graphql-tools-4.0.5.tgz", + "integrity": "sha512-kQCh3IZsMqquDx7zfIGWBau42xe46gmqabwYkpPlCLIjcEY1XK+auP7iGRD9/205BPyoQdY8hT96MPpgERdC9Q==", + "requires": { + "apollo-link": "^1.2.3", + "apollo-utilities": "^1.0.1", + "deprecated-decorator": "^0.1.6", + "iterall": "^1.1.3", + "uuid": "^3.1.0" + } + }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -3557,6 +3642,11 @@ "resolved": "https://registry.npmjs.org/nocache/-/nocache-2.1.0.tgz", "integrity": "sha512-0L9FvHG3nfnnmaEQPjT9xhfN4ISk0A8/2j4M37Np4mcDesJjHgEUfgPhdCyZuFI954tjokaIj/A3NdpFNdEh4Q==" }, + "node-fetch": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" + }, "node-pre-gyp": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.12.0.tgz", @@ -5052,11 +5142,18 @@ } } }, + "ts-invariant": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/ts-invariant/-/ts-invariant-0.4.4.tgz", + "integrity": "sha512-uEtWkFM/sdZvRNNDL3Ehu4WVpwaulhwQszV8mrtcdeE8nN00BV9mAmQ88RkrBhFgl9gMgvjJLAQcZbnPXI9mlA==", + "requires": { + "tslib": "^1.9.3" + } + }, "tslib": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", - "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==", - "dev": true + "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==" }, "type-check": { "version": "0.3.2", @@ -5404,6 +5501,20 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==" + }, + "zen-observable": { + "version": "0.8.14", + "resolved": "https://registry.npmjs.org/zen-observable/-/zen-observable-0.8.14.tgz", + "integrity": "sha512-kQz39uonEjEESwh+qCi83kcC3rZJGh4mrZW7xjkSQYXkq//JZHTtKo+6yuVloTgMtzsIWOJrjIrKvk/dqm0L5g==" + }, + "zen-observable-ts": { + "version": "0.8.20", + "resolved": "https://registry.npmjs.org/zen-observable-ts/-/zen-observable-ts-0.8.20.tgz", + "integrity": "sha512-2rkjiPALhOtRaDX6pWyNqK1fnP5KkJJybYebopNSn6wDG1lxBoFs2+nwwXKoA6glHIrtwrfBBy6da0stkKtTAA==", + "requires": { + "tslib": "^1.9.3", + "zen-observable": "^0.8.0" + } } } } diff --git a/package.json b/package.json index 10bd212..cccabc6 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "nodemon -r dotenv/config src/server.js", + "start": "nodemon -r dotenv/config src/server", "lint": "eslint --ignore-path .gitignore ." }, "husky": { @@ -24,15 +24,18 @@ }, "homepage": "https://github.com/RisingStack/jsconfbp-2019-graphql#readme", "dependencies": { + "apollo-link-http": "1.5.16", "axios": "0.19.0", "bcrypt": "^3.0.6", "cors": "^2.8.5", "express": "^4.17.1", "express-graphql": "^0.9.0", "graphql": "^14.5.4", + "graphql-tools": "4.0.5", "helmet": "^3.21.0", "knex": "^0.19.3", "lodash": "^4.17.15", + "node-fetch": "2.6.0", "pg": "^7.12.1", "uuidv4": "^5.0.1" }, diff --git a/scripts/createTestData.js b/scripts/createTestData.js index 27c6a55..0ff4fef 100755 --- a/scripts/createTestData.js +++ b/scripts/createTestData.js @@ -3,7 +3,7 @@ require('dotenv/config'); -const db = require('../src/db'); +const db = require('../src/server/db'); Promise.all(db.createTables()).then(() => { Promise.all(db.createTestData()).then(() => { diff --git a/scripts/dropTables.js b/scripts/dropTables.js index dcbef69..cf33ebe 100755 --- a/scripts/dropTables.js +++ b/scripts/dropTables.js @@ -3,7 +3,7 @@ require('dotenv/config'); -const db = require('../src/db'); +const db = require('../src/server/db'); Promise.all(db.dropTables()).then(() => { console.log('Tables dropped.'); diff --git a/src/config.js b/src/server/config.js similarity index 100% rename from src/config.js rename to src/server/config.js diff --git a/src/db.js b/src/server/db.js similarity index 100% rename from src/db.js rename to src/server/db.js diff --git a/src/fetcher.js b/src/server/fetcher.js similarity index 100% rename from src/fetcher.js rename to src/server/fetcher.js diff --git a/src/gqlSchema.js b/src/server/gqlSchema.js similarity index 100% rename from src/gqlSchema.js rename to src/server/gqlSchema.js diff --git a/src/server.js b/src/server/index.js similarity index 86% rename from src/server.js rename to src/server/index.js index a2d2ebd..6f3586f 100644 --- a/src/server.js +++ b/src/server/index.js @@ -2,6 +2,8 @@ const express = require('express'); const graphqlHTTP = require('express-graphql'); const helmet = require('helmet'); const cors = require('cors'); +const { mergeSchemas } = require('graphql-tools'); +const pokemonSchema = require('./pokemonSchema'); const db = require('./db'); @@ -25,7 +27,9 @@ app.use(cors({ })); app.use('/graphql', graphqlHTTP(async () => ({ - schema, + schema: mergeSchemas({ + schemas: [schema, await pokemonSchema()], + }), // rootValue, graphiql: true, customFormatErrorFn: (error) => { diff --git a/src/server/pokemonSchema.js b/src/server/pokemonSchema.js new file mode 100644 index 0000000..2a089ef --- /dev/null +++ b/src/server/pokemonSchema.js @@ -0,0 +1,16 @@ +const { HttpLink } = require('apollo-link-http'); +const fetch = require('node-fetch'); +const { makeRemoteExecutableSchema, introspectSchema } = require('graphql-tools'); + +const link = new HttpLink({ uri: 'https://graphql-pokemon.now.sh', fetch }); + +module.exports = async () => { + const schema = await introspectSchema(link); + + const executableSchema = makeRemoteExecutableSchema({ + schema, + link, + }); + + return executableSchema; +}; diff --git a/src/schema.js b/src/server/schema.js similarity index 100% rename from src/schema.js rename to src/server/schema.js diff --git a/src/schema/comment.js b/src/server/schema/comment.js similarity index 100% rename from src/schema/comment.js rename to src/server/schema/comment.js diff --git a/src/schema/common.js b/src/server/schema/common.js similarity index 100% rename from src/schema/common.js rename to src/server/schema/common.js diff --git a/src/schema/post.js b/src/server/schema/post.js similarity index 100% rename from src/schema/post.js rename to src/server/schema/post.js diff --git a/src/schema/user.js b/src/server/schema/user.js similarity index 100% rename from src/schema/user.js rename to src/server/schema/user.js diff --git a/src/schema/weather.js b/src/server/schema/weather.js similarity index 100% rename from src/schema/weather.js rename to src/server/schema/weather.js