diff --git a/package-lock.json b/package-lock.json index d96baf5..b5faa8f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3121,6 +3121,20 @@ "mimic-response": "^1.0.0" } }, + "codemirror": { + "version": "5.59.2", + "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.59.2.tgz", + "integrity": "sha512-/D5PcsKyzthtSy2NNKCyJi3b+htRkoKv3idswR/tR6UAvMNKA7SrmyZy6fOONJxSRs1JlUWEDAbxqfdArbK8iA==" + }, + "codemirror-graphql": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/codemirror-graphql/-/codemirror-graphql-0.15.2.tgz", + "integrity": "sha512-Hxod/lFyDV3kXXgnqVDzThpxIudBCH70yJ5YospeBAFqdHpd8dgsJLIAlIxeqT3x5hcdWu1Rd1RI3qx84FTvMg==", + "requires": { + "graphql-language-service-interface": "^2.8.2", + "graphql-language-service-parser": "^1.9.0" + } + }, "collection-visit": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/collection-visit/-/collection-visit-1.0.0.tgz", @@ -3412,6 +3426,14 @@ "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=", "dev": true }, + "copy-to-clipboard": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/copy-to-clipboard/-/copy-to-clipboard-3.3.1.tgz", + "integrity": "sha512-i13qo6kIHTTpCm8/Wup+0b1mVWETvu2kIMzKoK8FpkLkFxlt0znUAHcMzox+T8sPlqtZXq3CulEjQHsYiGFJUw==", + "requires": { + "toggle-selection": "^1.0.6" + } + }, "core-js": { "version": "3.8.3", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.8.3.tgz", @@ -4521,8 +4543,7 @@ "entities": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/entities/-/entities-2.2.0.tgz", - "integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==", - "dev": true + "integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==" }, "env-paths": { "version": "2.2.0", @@ -4827,6 +4848,71 @@ } } }, + "express-graphql": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/express-graphql/-/express-graphql-0.12.0.tgz", + "integrity": "sha512-DwYaJQy0amdy3pgNtiTDuGGM2BLdj+YO2SgbKoLliCfuHv3VVTt7vNG/ZqK2hRYjtYHE2t2KB705EU94mE64zg==", + "requires": { + "accepts": "^1.3.7", + "content-type": "^1.0.4", + "http-errors": "1.8.0", + "raw-body": "^2.4.1" + }, + "dependencies": { + "bytes": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", + "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" + }, + "http-errors": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.0.tgz", + "integrity": "sha512-4I8r0C5JDhT5VkvI47QktDW75rNlGVsUf/8hzjCC/wkWI/jdTRmBb9aI7erSG82r1bjKY3F6k28WnsVxB1C73A==", + "requires": { + "depd": "~1.1.2", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": ">= 1.5.0 < 2", + "toidentifier": "1.0.0" + } + }, + "raw-body": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.1.tgz", + "integrity": "sha512-9WmIKF6mkvA0SLmA2Knm9+qj89e+j1zqgyn8aXGd7+nAduPoqgI9lO57SAZNn/Byzo5P7JhXTyg9PzaJbH73bA==", + "requires": { + "bytes": "3.1.0", + "http-errors": "1.7.3", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + }, + "dependencies": { + "http-errors": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.3.tgz", + "integrity": "sha512-ZTTX0MWrsQ2ZAhA1cejAwDLycFsd7I7nVtnkT3Ol0aqodaKW+0CTZDQ1uBv5whptCnc8e8HeRRJxRs0kmm/Qfw==", + "requires": { + "depd": "~1.1.2", + "inherits": "2.0.4", + "setprototypeof": "1.1.1", + "statuses": ">= 1.5.0 < 2", + "toidentifier": "1.0.0" + } + }, + "setprototypeof": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", + "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" + } + } + }, + "setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + } + } + }, "extend-shallow": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-3.0.2.tgz", @@ -5446,6 +5532,66 @@ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==" }, + "graphiql": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/graphiql/-/graphiql-1.3.2.tgz", + "integrity": "sha512-huo1Uxkcb1wpCGlDjE1N5X3dUrBTnOlj7/VgXwFUF0mcq/l/5RBTYx49pAc92DXO7rx715ZtUtAL60PxzGeh+w==", + "requires": { + "codemirror": "^5.54.0", + "codemirror-graphql": "^0.15.2", + "copy-to-clipboard": "^3.2.0", + "entities": "^2.0.0", + "graphql-language-service": "^3.1.2", + "markdown-it": "^10.0.0" + } + }, + "graphql": { + "version": "15.5.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.5.0.tgz", + "integrity": "sha512-OmaM7y0kaK31NKG31q4YbD2beNYa6jBBKtMFT6gLYJljHLJr42IqJ8KX08u3Li/0ifzTU5HjmoOOrwa5BRLeDA==" + }, + "graphql-language-service": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/graphql-language-service/-/graphql-language-service-3.1.2.tgz", + "integrity": "sha512-OiOH8mVE+uotrl3jGA2Pgt9k7rrI8lgw/8p+Cf6nwyEHbmIZj37vX9KoOWgpdFhuQlw824nNxWHSbz6k90xjWQ==", + "requires": { + "graphql-language-service-interface": "^2.8.2", + "graphql-language-service-types": "^1.8.0" + } + }, + "graphql-language-service-interface": { + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/graphql-language-service-interface/-/graphql-language-service-interface-2.8.2.tgz", + "integrity": "sha512-otbOQmhgkAJU1QJgQkMztNku6SbJLu/uodoFOYOOtJsizTjrMs93vkYaHCcYnLA3oi1Goj27XcHjMnRCYQOZXQ==", + "requires": { + "graphql-language-service-parser": "^1.9.0", + "graphql-language-service-types": "^1.8.0", + "graphql-language-service-utils": "^2.5.1", + "vscode-languageserver-types": "^3.15.1" + } + }, + "graphql-language-service-parser": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/graphql-language-service-parser/-/graphql-language-service-parser-1.9.0.tgz", + "integrity": "sha512-B5xPZLbBmIp0kHvpY1Z35I5DtPoDK9wGxQVRDIzcBaiIvAmlTrDvjo3bu7vKREdjFbYKvWNgrEWENuprMbF17Q==", + "requires": { + "graphql-language-service-types": "^1.8.0" + } + }, + "graphql-language-service-types": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/graphql-language-service-types/-/graphql-language-service-types-1.8.1.tgz", + "integrity": "sha512-IpYS0mEHEmRsFlq+loWCpSYYYizAID7Alri6GoFN1QqUdux+8rp1Tkp2NGsGDpDmm3Dbz5ojmJWzNWQGpuwveA==" + }, + "graphql-language-service-utils": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/graphql-language-service-utils/-/graphql-language-service-utils-2.5.1.tgz", + "integrity": "sha512-Lzz723cYrYlVN4WVzIyFGg3ogoe+QYAIBfdtDboiIILoy0FTmqbyC2TOErqbmWKqO4NK9xDA95cSRFbWiHYj0g==", + "requires": { + "graphql-language-service-types": "^1.8.0", + "nullthrows": "^1.0.0" + } + }, "handle-thing": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/handle-thing/-/handle-thing-2.0.1.tgz", @@ -6390,6 +6536,14 @@ "immediate": "~3.0.5" } }, + "linkify-it": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.2.0.tgz", + "integrity": "sha512-GnAl/knGn+i1U/wjBz3akz2stz+HrHLsxMwHQGofCDfPvlf+gDKN58UtfmUquTY4/MXeE2x7k19KQmeoZi94Iw==", + "requires": { + "uc.micro": "^1.0.1" + } + }, "load-json-file": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", @@ -6461,6 +6615,11 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==" }, + "lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=" + }, "lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", @@ -6553,6 +6712,25 @@ "object-visit": "^1.0.0" } }, + "markdown-it": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-10.0.0.tgz", + "integrity": "sha512-YWOP1j7UbDNz+TumYP1kpwnP0aEa711cJjrAQrzd0UXlbJfc5aAq0F/PZHjiioqDC1NKgvIMX+o+9Bk7yuM2dg==", + "requires": { + "argparse": "^1.0.7", + "entities": "~2.0.0", + "linkify-it": "^2.0.0", + "mdurl": "^1.0.1", + "uc.micro": "^1.0.5" + }, + "dependencies": { + "entities": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/entities/-/entities-2.0.3.tgz", + "integrity": "sha512-MyoZ0jgnLvB2X3Lg5HqpFmn1kybDiIfEQmKzTb5apr51Rb+T3KdmMiqa70T+bhGnyv7bQ6WMj2QMHpGMmlrUYQ==" + } + } + }, "matcher": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/matcher/-/matcher-3.0.0.tgz", @@ -6572,6 +6750,11 @@ } } }, + "mdurl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", + "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=" + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -7124,6 +7307,11 @@ "boolbase": "~1.0.0" } }, + "nullthrows": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/nullthrows/-/nullthrows-1.1.1.tgz", + "integrity": "sha512-2vPPEi+Z7WqML2jZYddDIfy5Dqb0r2fze2zTxNNknZaFpVHU3mFB3R+DWeJWGVx0ecvttSGlJTI+WG+8Z4cDWw==" + }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -9362,6 +9550,11 @@ "is-number": "^7.0.0" } }, + "toggle-selection": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/toggle-selection/-/toggle-selection-1.0.6.tgz", + "integrity": "sha1-bkWxJj8gF/oKzH2J14sVuL932jI=" + }, "toidentifier": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", @@ -9450,6 +9643,11 @@ "resolved": "https://registry.npmjs.org/typical/-/typical-2.6.1.tgz", "integrity": "sha1-XAgOXWYcu+OCWdLnCjxyU+hziB0=" }, + "uc.micro": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", + "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==" + }, "undefsafe": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.3.tgz", @@ -9750,6 +9948,11 @@ "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" }, + "vscode-languageserver-types": { + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz", + "integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==" + }, "wait-on": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/wait-on/-/wait-on-5.2.1.tgz", diff --git a/package.json b/package.json index 94d941c..b89a690 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "homepage": "./", "scripts": { "prod": "webpack --mode production --config webpack.build.config.js && electron --noDevServer .", - "start": "webpack serve --hot --host 0.0.0.0 --config=./webpack.dev.config.js --mode development", + "start": "webpack serve --hot --host localhost --config=./webpack.dev.config.js --mode development", "build": "webpack --config webpack.build.config.js --mode production", "package": "npm run build", "postpackage": "electron-packager ./ --out=./builds" @@ -48,7 +48,12 @@ "electron-fetch": "^1.7.3", "electron-is-dev": "^1.2.0", "express": "^4.17.1", + "express-graphql": "^0.12.0", "extract-mongo-schema": "^0.2.10", + "graphiql": "^1.3.2", + "graphql": "^15.5.0", + "lodash": "^4.17.20", + "lodash.clonedeep": "^4.5.0", "mongodb": "^3.6.4", "mongoose": "^5.11.14", "react": "^17.0.1", diff --git a/server/schema.js b/server/schema.js new file mode 100644 index 0000000..3a487ea --- /dev/null +++ b/server/schema.js @@ -0,0 +1,113 @@ +const graphql = require('graphql'); +var cloneDeep = require('lodash.clonedeep'); +const { + GraphQLObjectType, + GraphQLString, + GraphQLSchema, + GraphQLID, + GraphQLInt, + GraphQLList, +} = graphql; + + +const dummyData = + { + users: { + _id: { + primaryKey: true, + type: "Object", + required: true, + }, + name: { + type: "string", + required: true, + }, + password: { + type: "string", + required: true, + }, + username: { + type: "string", + required: true, + }, + }, + conversations: { + _id: { + primaryKey: true, + type: "string", + required: true, + }, + participants: { + type: "Array", + required: true, + }, + messages: { + type: "Array", + required: true, + }, + }, + } + + const capitalize = (s) => { + if (typeof s !== 'string') return '' + return s.charAt(0).toUpperCase() + s.slice(1) +} + let obj = {} + +let fieldsObj = {} +for (const property in dummyData) { + + for (const [key, value] of Object.entries(dummyData[property])) { + fieldsObj[key] = {type: GraphQLString} + } + var deep = cloneDeep(fieldsObj); + console.log(deep === fieldsObj); + + obj[capitalize(`${property}Type`)] = new GraphQLObjectType({ + name: capitalize(property), + fields: () => (deep) + }) + console.log('HEREEEEEEEEEEEEEEEEEEEE',fieldsObj, obj) + fieldsObj = {} +} + + +const RootQuery = new GraphQLObjectType({ + name: 'RootQueryType', + fields: { + // entry points into graphql queries + user: { + type: obj.UsersType, + // getting one type of book. tell args that id will be passed in and it will be of type ID. + args: { id: { type: GraphQLID } }, + resolve(parent, args) { + // code to get data from db + // return _.find(books, { id: args.id }); + return _.find({}); + }, + }, + // author: { + // type: AuthorType, + // args: { id: { type: GraphQLID } }, + // 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; + // }, + // }, + }, +}); + +module.exports = new GraphQLSchema({ + query: RootQuery, +}) \ No newline at end of file diff --git a/server/server.js b/server/server.js index 244827b..879a0a9 100644 --- a/server/server.js +++ b/server/server.js @@ -8,6 +8,8 @@ const MongoClient = require("mongodb").MongoClient; // Executing terminal commands using JS const { exec } = require("child_process"); + + const mongoSchemaController = require('./controllers/mongoSchemaController') console.log("SERVER RUNNING"); @@ -23,6 +25,13 @@ app.post("/getURI", mongoSchemaController.createMongoSchema, (req, res, next) => }, 2000) }) + +const {graphqlHTTP} = require('express-graphql') +const schema = require('./schema') + +app.use('/graphql', graphqlHTTP({ schema, graphiql: true })) + + // app.use('/dist', express.static(path.join(__dirname, '../dist'))); // app.get('/', (req, res) => {