From 7e24faca56a49a1867d6761ac4733027077bac7b Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Tue, 6 Mar 2018 10:03:44 +0000 Subject: [PATCH 01/15] added lesson 5 code --- server/.gitignore | 59 +++++++++ server/app.js | 7 ++ server/package-lock.json | 254 +++++++++++++++++++++++++++++++++++++++ server/package.json | 14 +++ 4 files changed, 334 insertions(+) create mode 100644 server/.gitignore create mode 100644 server/app.js create mode 100644 server/package-lock.json create mode 100644 server/package.json diff --git a/server/.gitignore b/server/.gitignore new file mode 100644 index 0000000..00cbbdf --- /dev/null +++ b/server/.gitignore @@ -0,0 +1,59 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + diff --git a/server/app.js b/server/app.js new file mode 100644 index 0000000..8cba26e --- /dev/null +++ b/server/app.js @@ -0,0 +1,7 @@ +const express = require('express'); + +const app = express(); + +app.listen(4000, () => { + console.log('now listening for requests on port 4000'); +}); diff --git a/server/package-lock.json b/server/package-lock.json new file mode 100644 index 0000000..6d3e58f --- /dev/null +++ b/server/package-lock.json @@ -0,0 +1,254 @@ +{ + "name": "server", + "version": "1.0.0", + "lockfileVersion": 1, + "dependencies": { + "accepts": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", + "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=" + }, + "array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" + }, + "body-parser": { + "version": "1.18.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", + "integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=" + }, + "bytes": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", + "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=" + }, + "content-disposition": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", + "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" + }, + "content-type": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", + "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" + }, + "cookie": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", + "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" + }, + "cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==" + }, + "depd": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" + }, + "destroy": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" + }, + "ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" + }, + "encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" + }, + "escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" + }, + "etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" + }, + "express": { + "version": "4.16.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.16.2.tgz", + "integrity": "sha1-41xt/i1kt9ygpc1PIXgb4ymeB2w=" + }, + "finalhandler": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.0.tgz", + "integrity": "sha1-zgtoVbRYU+eRsvzGgARtiCU91/U=" + }, + "forwarded": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", + "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" + }, + "fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" + }, + "http-errors": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", + "integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=", + "dependencies": { + "depd": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", + "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=" + }, + "setprototypeof": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", + "integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=" + } + } + }, + "iconv-lite": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "ipaddr.js": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.6.0.tgz", + "integrity": "sha1-4/o1e3c9phnybpXwSdBVxyeW+Gs=" + }, + "media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" + }, + "merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" + }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" + }, + "mime": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", + "integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==" + }, + "mime-db": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz", + "integrity": "sha512-BHJ/EKruNIqJf/QahvxwQZXKygOQ256myeN/Ew+THcAa5q+PjyTTMMeNQC4DZw5AwfvelsUrA6B67NKMqXDbzQ==" + }, + "mime-types": { + "version": "2.1.18", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.18.tgz", + "integrity": "sha512-lc/aahn+t4/SWV/qcmumYjymLsWfN3ELhpmVuUFjgsORruuZPVSwAQryq+HHGvO/SI2KVX26bx+En+zhM8g8hQ==" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "negotiator": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", + "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" + }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=" + }, + "parseurl": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", + "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" + }, + "path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" + }, + "proxy-addr": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.3.tgz", + "integrity": "sha512-jQTChiCJteusULxjBp8+jftSQE5Obdl3k4cnmLA6WXtK6XFuWRnvVL7aCiBqaLPM8c4ph0S4tKna8XvmIwEnXQ==" + }, + "qs": { + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", + "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" + }, + "range-parser": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", + "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" + }, + "raw-body": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz", + "integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=" + }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" + }, + "send": { + "version": "0.16.1", + "resolved": "https://registry.npmjs.org/send/-/send-0.16.1.tgz", + "integrity": "sha512-ElCLJdJIKPk6ux/Hocwhk7NFHpI3pVm/IZOYWqUmoxcgeyM+MpxHHKhb8QmlJDX1pU6WrgaHBkVNm73Sv7uc2A==" + }, + "serve-static": { + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.1.tgz", + "integrity": "sha512-hSMUZrsPa/I09VYFJwa627JJkNs0NrfL1Uzuup+GqHfToR2KcsXFymXSV90hoyw3M+msjFuQly+YzIH/q0MGlQ==" + }, + "setprototypeof": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", + "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" + }, + "statuses": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", + "integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4=" + }, + "type-is": { + "version": "1.6.16", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz", + "integrity": "sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q==" + }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" + }, + "utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" + }, + "vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" + } + } +} diff --git a/server/package.json b/server/package.json new file mode 100644 index 0000000..472c3f3 --- /dev/null +++ b/server/package.json @@ -0,0 +1,14 @@ +{ + "name": "server", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "express": "^4.16.2" + } +} From 1a4fc586fa7ae1626b759a814617ab50d369c053 Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Tue, 6 Mar 2018 10:27:20 +0000 Subject: [PATCH 02/15] lesson 6 code --- server/app.js | 5 +++++ server/package-lock.json | 15 +++++++++++++++ server/package.json | 4 +++- server/schema/schema.js | 0 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 server/schema/schema.js diff --git a/server/app.js b/server/app.js index 8cba26e..1192d03 100644 --- a/server/app.js +++ b/server/app.js @@ -2,6 +2,11 @@ const express = require('express'); const app = express(); +// bind express with graphql +app.use('/graphql', expressGraphQL({ + // pass in a schema property +})) + app.listen(4000, () => { console.log('now listening for requests on port 4000'); }); diff --git a/server/package-lock.json b/server/package-lock.json index 6d3e58f..3caee82 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -83,6 +83,11 @@ "resolved": "https://registry.npmjs.org/express/-/express-4.16.2.tgz", "integrity": "sha1-41xt/i1kt9ygpc1PIXgb4ymeB2w=" }, + "express-graphql": { + "version": "0.6.12", + "resolved": "https://registry.npmjs.org/express-graphql/-/express-graphql-0.6.12.tgz", + "integrity": "sha512-ouLWV0hRw4hnaLtXzzwhdC79ewxKbY2PRvm05mPc/zOH5W5WVCHDQ1SmNxEPBQdUeeSNh29aIqW9zEQkA3kMuA==" + }, "finalhandler": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.0.tgz", @@ -98,6 +103,11 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, + "graphql": { + "version": "0.13.1", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-0.13.1.tgz", + "integrity": "sha512-awNp3LTrQ7dJDSX3p3PBuxNDC+WFSOrWeV6+l4Xeh2PQJVOFyQ9SZPonXRz2WZc7aIxLZsf2nDZuuuc0qyEq/A==" + }, "http-errors": { "version": "1.6.2", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", @@ -130,6 +140,11 @@ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.6.0.tgz", "integrity": "sha1-4/o1e3c9phnybpXwSdBVxyeW+Gs=" }, + "iterall": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/iterall/-/iterall-1.2.2.tgz", + "integrity": "sha512-yynBb1g+RFUPY64fTrFv7nsjRrENBQJaX2UL+2Szc9REFrSNm1rpSXHGzhmAy7a9uv3vlvgBlXnf9RqmPH1/DA==" + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", diff --git a/server/package.json b/server/package.json index 472c3f3..ed87b3a 100644 --- a/server/package.json +++ b/server/package.json @@ -9,6 +9,8 @@ "author": "", "license": "ISC", "dependencies": { - "express": "^4.16.2" + "express": "^4.16.2", + "express-graphql": "^0.6.12", + "graphql": "^0.13.1" } } diff --git a/server/schema/schema.js b/server/schema/schema.js new file mode 100644 index 0000000..e69de29 From a1df1069887dcfd8c55a2f0f82149675ff896af3 Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Tue, 6 Mar 2018 10:32:59 +0000 Subject: [PATCH 03/15] lesson 5 code update --- server/app.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/app.js b/server/app.js index 1192d03..c1b457b 100644 --- a/server/app.js +++ b/server/app.js @@ -1,11 +1,12 @@ const express = require('express'); +const graphqlHTTP = require('express-graphql'); const app = express(); // bind express with graphql -app.use('/graphql', expressGraphQL({ +app.use('/graphql', graphqlHTTP({ // pass in a schema property -})) +})); app.listen(4000, () => { console.log('now listening for requests on port 4000'); From 80b0f016e04d3ac589b609724715e57fe2d7f575 Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Thu, 8 Mar 2018 09:11:05 +0000 Subject: [PATCH 04/15] lesson 7 code --- server/schema/schema.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/schema/schema.js b/server/schema/schema.js index e69de29..05c5b35 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -0,0 +1,12 @@ +const graphql = require('graphql'); + +const { GraphQLObjectType, GraphQLString } = graphql; + +const BookType = new GraphQLObjectType({ + name: 'Book', + fields: ( ) => ({ + id: { type: GraphQLString }, + name: { type: GraphQLString }, + genre: { type: GraphQLString } + }); +}); From bcd9bc160e3c408308348905a69ab4ade1237fb0 Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Thu, 8 Mar 2018 10:29:48 +0000 Subject: [PATCH 05/15] lesson 8 code --- server/app.js | 3 ++- server/schema/schema.js | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/server/app.js b/server/app.js index c1b457b..35a5ae2 100644 --- a/server/app.js +++ b/server/app.js @@ -1,11 +1,12 @@ const express = require('express'); const graphqlHTTP = require('express-graphql'); +const schema = require('./schema/schema'); const app = express(); // bind express with graphql app.use('/graphql', graphqlHTTP({ - // pass in a schema property + schema })); app.listen(4000, () => { diff --git a/server/schema/schema.js b/server/schema/schema.js index 05c5b35..0fc6227 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -1,6 +1,6 @@ const graphql = require('graphql'); -const { GraphQLObjectType, GraphQLString } = graphql; +const { GraphQLObjectType, GraphQLString, GraphQLSchema } = graphql; const BookType = new GraphQLObjectType({ name: 'Book', @@ -10,3 +10,21 @@ const BookType = new GraphQLObjectType({ genre: { type: GraphQLString } }); }); + +const RootQuery = new GraphQLObjectType({ + name: 'RootQueryType', + fields: { + book: { + type: BookType, + args: { id: { type: GraphQlString } }, + resolve(parent, args){ + // code to get data from db / other source + + } + } + } +}); + +module.exports = new GraphQLSchema({ + query: RootQuery +}); From f9a7cba62f987ec46446ea931f2944502044041e Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Thu, 8 Mar 2018 10:39:10 +0000 Subject: [PATCH 06/15] lesson 9 code --- server/package-lock.json | 5 +++++ server/package.json | 3 ++- server/schema/schema.js | 12 ++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/server/package-lock.json b/server/package-lock.json index 3caee82..d02653c 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -145,6 +145,11 @@ "resolved": "https://registry.npmjs.org/iterall/-/iterall-1.2.2.tgz", "integrity": "sha512-yynBb1g+RFUPY64fTrFv7nsjRrENBQJaX2UL+2Szc9REFrSNm1rpSXHGzhmAy7a9uv3vlvgBlXnf9RqmPH1/DA==" }, + "lodash": { + "version": "4.17.5", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", + "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==" + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", diff --git a/server/package.json b/server/package.json index ed87b3a..60ee8cd 100644 --- a/server/package.json +++ b/server/package.json @@ -11,6 +11,7 @@ "dependencies": { "express": "^4.16.2", "express-graphql": "^0.6.12", - "graphql": "^0.13.1" + "graphql": "^0.13.1", + "lodash": "^4.17.5" } } diff --git a/server/schema/schema.js b/server/schema/schema.js index 0fc6227..6052afc 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -1,7 +1,15 @@ const graphql = require('graphql'); +const _ = require('lodash'); const { GraphQLObjectType, GraphQLString, GraphQLSchema } = graphql; +// dummy data +var books = [ + { name: 'Name of the Wind', genre: 'Fantasy', id: '1' }, + { name: 'The Final Empire', genre: 'Fantasy', id: '2' }, + { name: 'The Long Earth', genre: 'Sci-Fi', id: '3' }, +]; + const BookType = new GraphQLObjectType({ name: 'Book', fields: ( ) => ({ @@ -16,10 +24,10 @@ const RootQuery = new GraphQLObjectType({ fields: { book: { type: BookType, - args: { id: { type: GraphQlString } }, + args: { id: { type: GraphQLString } }, resolve(parent, args){ // code to get data from db / other source - + return _.find(books, { id: args.id }); } } } From eb3042a1ea89cea7fd9499eb383ae96ae074ec5f Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Thu, 8 Mar 2018 10:49:02 +0000 Subject: [PATCH 07/15] lesson 10 code --- server/app.js | 3 ++- server/schema/schema.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/app.js b/server/app.js index 35a5ae2..b2d5cda 100644 --- a/server/app.js +++ b/server/app.js @@ -6,7 +6,8 @@ const app = express(); // bind express with graphql app.use('/graphql', graphqlHTTP({ - schema + schema, + graphiql: true })); app.listen(4000, () => { diff --git a/server/schema/schema.js b/server/schema/schema.js index 6052afc..a608913 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -16,7 +16,7 @@ const BookType = new GraphQLObjectType({ id: { type: GraphQLString }, name: { type: GraphQLString }, genre: { type: GraphQLString } - }); + }) }); const RootQuery = new GraphQLObjectType({ From a92a7ecafe628476b0d30ce92f4c9ebfd3f10632 Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Thu, 8 Mar 2018 17:04:37 +0000 Subject: [PATCH 08/15] lesson 11 code --- server/schema/schema.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server/schema/schema.js b/server/schema/schema.js index a608913..4b8e861 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -1,7 +1,12 @@ const graphql = require('graphql'); const _ = require('lodash'); -const { GraphQLObjectType, GraphQLString, GraphQLSchema } = graphql; +const { + GraphQLObjectType, + GraphQLString, + GraphQLSchema, + GraphQLID +} = graphql; // dummy data var books = [ @@ -13,7 +18,7 @@ var books = [ const BookType = new GraphQLObjectType({ name: 'Book', fields: ( ) => ({ - id: { type: GraphQLString }, + id: { type: GraphQLID }, name: { type: GraphQLString }, genre: { type: GraphQLString } }) @@ -24,9 +29,10 @@ const RootQuery = new GraphQLObjectType({ fields: { book: { type: BookType, - args: { id: { type: GraphQLString } }, + args: { id: { type: GraphQLID } }, resolve(parent, args){ // code to get data from db / other source + console.log(typeof(args.id)); return _.find(books, { id: args.id }); } } From f3c0fe5e1a72334b55b7beff3b7685a34992a0a8 Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Fri, 9 Mar 2018 09:28:46 +0000 Subject: [PATCH 09/15] lesson 12 code --- server/schema/schema.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/server/schema/schema.js b/server/schema/schema.js index 4b8e861..d441078 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -5,7 +5,8 @@ const { GraphQLObjectType, GraphQLString, GraphQLSchema, - GraphQLID + GraphQLID, + GraphQLInt } = graphql; // dummy data @@ -15,6 +16,12 @@ var books = [ { name: 'The Long Earth', genre: 'Sci-Fi', id: '3' }, ]; +var authors = [ + { name: 'Patrick Rothfuss', age: 44, id: '1' }, + { name: 'Brandon Sanderson', age: 42, id: '2' }, + { name: 'Terry Pratchett', age: 66, id: '3' } +]; + const BookType = new GraphQLObjectType({ name: 'Book', fields: ( ) => ({ @@ -24,6 +31,15 @@ const BookType = new GraphQLObjectType({ }) }); +const AuthorType = new GraphQLObjectType({ + name: 'Author', + fields: ( ) => ({ + id: { type: GraphQLID }, + name: { type: GraphQLString }, + age: { type: GraphQLInt } + }) +}); + const RootQuery = new GraphQLObjectType({ name: 'RootQueryType', fields: { @@ -32,9 +48,15 @@ const RootQuery = new GraphQLObjectType({ args: { id: { type: GraphQLID } }, resolve(parent, args){ // code to get data from db / other source - console.log(typeof(args.id)); return _.find(books, { id: args.id }); } + }, + author: { + type: AuthorType, + args: { id: { type: GraphQLID } }, + resolve(parent, args){ + return _.find(authors, { id: args.id }); + } } } }); From 677db3fc919390bf098d66712e66879bfaeb08ee Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Fri, 9 Mar 2018 09:39:32 +0000 Subject: [PATCH 10/15] lesson 13 code --- server/schema/schema.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server/schema/schema.js b/server/schema/schema.js index d441078..df0eb7f 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -11,9 +11,9 @@ const { // dummy data var books = [ - { name: 'Name of the Wind', genre: 'Fantasy', id: '1' }, - { name: 'The Final Empire', genre: 'Fantasy', id: '2' }, - { name: 'The Long Earth', genre: 'Sci-Fi', id: '3' }, + { name: 'Name of the Wind', genre: 'Fantasy', id: '1', authorId: '1' }, + { name: 'The Final Empire', genre: 'Fantasy', id: '2', authorId: '2' }, + { name: 'The Long Earth', genre: 'Sci-Fi', id: '3', authorId: '3' }, ]; var authors = [ @@ -27,7 +27,14 @@ const BookType = new GraphQLObjectType({ fields: ( ) => ({ id: { type: GraphQLID }, name: { type: GraphQLString }, - genre: { type: GraphQLString } + genre: { type: GraphQLString }, + author: { + type: AuthorType, + resolve(parent, args){ + console.log(parent); + return _.find(authors, { id: parent.authorId }); + } + } }) }); From e320434231f87d357f2597c456401005411f6495 Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Fri, 9 Mar 2018 10:45:00 +0000 Subject: [PATCH 11/15] lesson 14 code --- server/schema/schema.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/server/schema/schema.js b/server/schema/schema.js index df0eb7f..b52a8db 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -6,14 +6,18 @@ const { GraphQLString, GraphQLSchema, GraphQLID, - GraphQLInt + GraphQLInt, + GraphQLList } = graphql; // dummy data var books = [ { name: 'Name of the Wind', genre: 'Fantasy', id: '1', authorId: '1' }, { name: 'The Final Empire', genre: 'Fantasy', id: '2', authorId: '2' }, + { name: 'The Hero of Ages', genre: 'Fantasy', id: '4', authorId: '2' }, { name: 'The Long Earth', genre: 'Sci-Fi', id: '3', authorId: '3' }, + { name: 'The Colour of Magic', genre: 'Fantasy', id: '5', authorId: '3' }, + { name: 'The Light Fantastic', genre: 'Fantasy', id: '6', authorId: '3' }, ]; var authors = [ @@ -31,7 +35,6 @@ const BookType = new GraphQLObjectType({ author: { type: AuthorType, resolve(parent, args){ - console.log(parent); return _.find(authors, { id: parent.authorId }); } } @@ -43,7 +46,13 @@ const AuthorType = new GraphQLObjectType({ fields: ( ) => ({ id: { type: GraphQLID }, name: { type: GraphQLString }, - age: { type: GraphQLInt } + age: { type: GraphQLInt }, + books: { + type: new GraphQLList(BookType), + resolve(parent, args){ + return _.filter(books, { authorId: parent.id }); + } + } }) }); From 7ee61d9cd8478d5421af33cf5f37d2c721b81005 Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Fri, 9 Mar 2018 10:56:39 +0000 Subject: [PATCH 12/15] lesson 15 code --- server/schema/schema.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/schema/schema.js b/server/schema/schema.js index b52a8db..6cefa6a 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -73,6 +73,18 @@ const RootQuery = new GraphQLObjectType({ resolve(parent, args){ return _.find(authors, { id: args.id }); } + }, + books: { + type: new GraphQLList(BookType), + resolve(parent, args){ + return books; + } + }, + authors: { + type: new GraphQLList(AuthorType), + resolve(parent, args){ + return authors; + } } } }); From 7a0239ca0a597972bfdfe5b36d5919f6921d3e40 Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Fri, 9 Mar 2018 11:16:58 +0000 Subject: [PATCH 13/15] lesson 16 code --- server/app.js | 8 ++++ server/package-lock.json | 87 ++++++++++++++++++++++++++++++++++++++++ server/package.json | 3 +- 3 files changed, 97 insertions(+), 1 deletion(-) diff --git a/server/app.js b/server/app.js index b2d5cda..8ba75a2 100644 --- a/server/app.js +++ b/server/app.js @@ -1,9 +1,17 @@ const express = require('express'); const graphqlHTTP = require('express-graphql'); const schema = require('./schema/schema'); +const mongoose = require('mongoose'); const app = express(); +// connect to mlab database +// make sure to replace my db string & creds with your own +mongoose.connect('mongodb://ninja:test@ds161148.mlab.com:61148/graphql-ninja') +mongoose.connection.once('open', () => { + console.log('conneted to database'); +}); + // bind express with graphql app.use('/graphql', graphqlHTTP({ schema, diff --git a/server/package-lock.json b/server/package-lock.json index d02653c..d16ae58 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -13,11 +13,26 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, + "async": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.1.4.tgz", + "integrity": "sha1-LSFgx3iAMuTdbL4lAvH5osj2zeQ=" + }, + "bluebird": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.0.tgz", + "integrity": "sha1-eRQg1/VR7qKJdFOop3ZT+WYG1nw=" + }, "body-parser": { "version": "1.18.2", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", "integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=" }, + "bson": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/bson/-/bson-1.0.5.tgz", + "integrity": "sha512-D4SCtud6mlEb48kXdTHU31DRU0bsgOJ+4St1Dcx30uYNnf/aGc+hC9gHB/z0Eth8HYYs/hr0SFdyZViht19SwA==" + }, "bytes": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", @@ -145,11 +160,21 @@ "resolved": "https://registry.npmjs.org/iterall/-/iterall-1.2.2.tgz", "integrity": "sha512-yynBb1g+RFUPY64fTrFv7nsjRrENBQJaX2UL+2Szc9REFrSNm1rpSXHGzhmAy7a9uv3vlvgBlXnf9RqmPH1/DA==" }, + "kareem": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.0.5.tgz", + "integrity": "sha512-dfvpj3mCGJLZuADInhYrKaXkGarJxDqnTEiF91wK6fqwdCRmN+O4aEp8575UjZlQzDkzLI1WDL1uU7vyupURqw==" + }, "lodash": { "version": "4.17.5", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==" }, + "lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=" + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -180,6 +205,43 @@ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.18.tgz", "integrity": "sha512-lc/aahn+t4/SWV/qcmumYjymLsWfN3ELhpmVuUFjgsORruuZPVSwAQryq+HHGvO/SI2KVX26bx+En+zhM8g8hQ==" }, + "mongodb": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.0.4.tgz", + "integrity": "sha512-90YIIs7A4ko4kCGafxxXj3foexCAlJBC0YLwwIKgSLoE7Vni2IqUMz6HSsZ3zbXOfR1KWtxfnc0RyAMAY/ViLg==" + }, + "mongodb-core": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.0.4.tgz", + "integrity": "sha512-OTH267FjfwBdEufSnrgd+u8HuLWRuQ6p8DR0XirPl2BdlLEMh4XwjJf1RTlruILp5p2m1w8dDC8rCxibC3W8qQ==" + }, + "mongoose": { + "version": "5.0.9", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.0.9.tgz", + "integrity": "sha512-utGA97zd1R5NwRcqjhyPZP7sSExLQv9/KYAgFqtl6SRfp9vJXu5VPGwf6NdDRqUeh6e5v/tXVomkS2IPiSezxg==" + }, + "mongoose-legacy-pluralize": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz", + "integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ==" + }, + "mpath": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.3.0.tgz", + "integrity": "sha1-elj3iem1/TyUUgY0FXlg8mvV70Q=" + }, + "mquery": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.0.0.tgz", + "integrity": "sha512-WL1Lk8v4l8VFSSwN3yCzY9TXw+fKVYKn6f+w86TRzOLSE8k1yTgGaLBPUByJQi8VcLbOdnUneFV/y3Kv874pnQ==", + "dependencies": { + "sliced": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/sliced/-/sliced-0.0.5.tgz", + "integrity": "sha1-XtwETKTrb3gW1Qui/GPiXY/kcH8=" + } + } + }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -225,11 +287,31 @@ "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz", "integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=" }, + "regexp-clone": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-0.0.1.tgz", + "integrity": "sha1-p8LgmJH9vzj7sQ03b7cwA+aKxYk=" + }, + "require_optional": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz", + "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==" + }, + "resolve-from": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz", + "integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c=" + }, "safe-buffer": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" }, + "semver": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" + }, "send": { "version": "0.16.1", "resolved": "https://registry.npmjs.org/send/-/send-0.16.1.tgz", @@ -245,6 +327,11 @@ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" }, + "sliced": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz", + "integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E=" + }, "statuses": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", diff --git a/server/package.json b/server/package.json index 60ee8cd..14c0a57 100644 --- a/server/package.json +++ b/server/package.json @@ -12,6 +12,7 @@ "express": "^4.16.2", "express-graphql": "^0.6.12", "graphql": "^0.13.1", - "lodash": "^4.17.5" + "lodash": "^4.17.5", + "mongoose": "^5.0.9" } } From df2411953cff452b175704598dc839028481d271 Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Fri, 9 Mar 2018 13:12:47 +0000 Subject: [PATCH 14/15] lesson 17 code --- server/models/author.js | 13 +++++++++++++ server/models/book.js | 13 +++++++++++++ server/schema/schema.js | 31 ++++++++----------------------- 3 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 server/models/author.js create mode 100644 server/models/book.js diff --git a/server/models/author.js b/server/models/author.js new file mode 100644 index 0000000..69d46a1 --- /dev/null +++ b/server/models/author.js @@ -0,0 +1,13 @@ +const mongoose = require('mongoose'); +const Schema = mongoose.Schema; + +const authorSchema = new Schema({ + name: String, + age: Number, + books: [{ + type: Schema.Types.ObjectId, + ref: 'Book' + }] +}); + +module.exports = mongoose.model('Author', authorSchema); diff --git a/server/models/book.js b/server/models/book.js new file mode 100644 index 0000000..087f2df --- /dev/null +++ b/server/models/book.js @@ -0,0 +1,13 @@ +const mongoose = require('mongoose'); +const Schema = mongoose.Schema; + +const bookSchema = new Schema({ + name: String, + genre: String, + author: { + type: Schema.Types.ObjectId, + ref: 'Author' + } +}); + +module.exports = mongoose.model('Book', bookSchema); diff --git a/server/schema/schema.js b/server/schema/schema.js index 6cefa6a..e622389 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -1,4 +1,6 @@ const graphql = require('graphql'); +const Book = require('../models/book'); +const Author = require('../models/Author'); const _ = require('lodash'); const { @@ -10,22 +12,6 @@ const { GraphQLList } = graphql; -// dummy data -var books = [ - { name: 'Name of the Wind', genre: 'Fantasy', id: '1', authorId: '1' }, - { name: 'The Final Empire', genre: 'Fantasy', id: '2', authorId: '2' }, - { name: 'The Hero of Ages', genre: 'Fantasy', id: '4', authorId: '2' }, - { name: 'The Long Earth', genre: 'Sci-Fi', id: '3', authorId: '3' }, - { name: 'The Colour of Magic', genre: 'Fantasy', id: '5', authorId: '3' }, - { name: 'The Light Fantastic', genre: 'Fantasy', id: '6', authorId: '3' }, -]; - -var authors = [ - { name: 'Patrick Rothfuss', age: 44, id: '1' }, - { name: 'Brandon Sanderson', age: 42, id: '2' }, - { name: 'Terry Pratchett', age: 66, id: '3' } -]; - const BookType = new GraphQLObjectType({ name: 'Book', fields: ( ) => ({ @@ -35,7 +21,7 @@ const BookType = new GraphQLObjectType({ author: { type: AuthorType, resolve(parent, args){ - return _.find(authors, { id: parent.authorId }); + //return _.find(authors, { id: parent.authorId }); } } }) @@ -50,7 +36,7 @@ const AuthorType = new GraphQLObjectType({ books: { type: new GraphQLList(BookType), resolve(parent, args){ - return _.filter(books, { authorId: parent.id }); + //return _.filter(books, { authorId: parent.id }); } } }) @@ -63,27 +49,26 @@ const RootQuery = new GraphQLObjectType({ type: BookType, args: { id: { type: GraphQLID } }, resolve(parent, args){ - // code to get data from db / other source - return _.find(books, { id: args.id }); + //return _.find(books, { id: args.id }); } }, author: { type: AuthorType, args: { id: { type: GraphQLID } }, resolve(parent, args){ - return _.find(authors, { id: args.id }); + //return _.find(authors, { id: args.id }); } }, books: { type: new GraphQLList(BookType), resolve(parent, args){ - return books; + //return books; } }, authors: { type: new GraphQLList(AuthorType), resolve(parent, args){ - return authors; + //return authors; } } } From 7a11b2b4fcf3c3766098bf3da1aa2b12e5cac77a Mon Sep 17 00:00:00 2001 From: iamshaunjp Date: Fri, 9 Mar 2018 13:21:47 +0000 Subject: [PATCH 15/15] code refactor --- server/models/author.js | 6 +----- server/models/book.js | 5 +---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/server/models/author.js b/server/models/author.js index 69d46a1..84f4791 100644 --- a/server/models/author.js +++ b/server/models/author.js @@ -3,11 +3,7 @@ const Schema = mongoose.Schema; const authorSchema = new Schema({ name: String, - age: Number, - books: [{ - type: Schema.Types.ObjectId, - ref: 'Book' - }] + age: Number }); module.exports = mongoose.model('Author', authorSchema); diff --git a/server/models/book.js b/server/models/book.js index 087f2df..59af1da 100644 --- a/server/models/book.js +++ b/server/models/book.js @@ -4,10 +4,7 @@ const Schema = mongoose.Schema; const bookSchema = new Schema({ name: String, genre: String, - author: { - type: Schema.Types.ObjectId, - ref: 'Author' - } + authorId: String }); module.exports = mongoose.model('Book', bookSchema);