diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..61c41c4 --- /dev/null +++ b/.env.sample @@ -0,0 +1,2 @@ +PRISMA_HOST= +PRISMA_SECRET= \ No newline at end of file diff --git a/.gitignore b/.gitignore index c451fe7..57f0f97 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules/ .idea .env +.env.prod prisma/.env env.db diff --git a/.travis.yml b/.travis.yml index 5ce15e7..755d68b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,10 @@ language: node_js node_js: - "10" + +cache: + npm: true + services: - docker @@ -9,6 +13,11 @@ before_install: - npm install - docker-compose -f prisma/docker-compose.yml up -d +stages: + - test + - build + - deploy + jobs: include: - stage: test @@ -20,4 +29,15 @@ jobs: - stage: build script: - cd prisma && prisma generate && prisma deploy - - npm run build \ No newline at end of file + - npm run build + + - stage: deploy + script: + - cd prisma && prisma generate && prisma deploy && cd .. + - npm run build + - pip install --user awscli + - export PATH=$PATH:$HOME/.local/bin + - docker login --username $DOCKER_USER -p $DOCKER_PASS + - docker build -t rctechclub/phoenix:dev . + - docker push rctechclub/phoenix:dev + - aws ecs update-service --cluster phoenix-prod --service phoenix --force-new-deployment --region us-east-2 diff --git a/Dockerfile b/Dockerfile index 71fd96e..47f7328 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:10 +FROM node:10-alpine WORKDIR usr/src/app COPY package.json . RUN npm install diff --git a/__tests__/users.ts b/__tests__/users.ts index f1cf327..ee0e621 100644 --- a/__tests__/users.ts +++ b/__tests__/users.ts @@ -1,13 +1,12 @@ +import * as env from 'dotenv'; +env.config(); import { prisma } from '../src/generated/prisma-client'; import typeDefs from '../src/schema'; import resolvers from '../src/resolvers'; -import * as env from 'dotenv'; const { ApolloServer, gql } = require('apollo-server'); const { createTestClient } = require('apollo-server-testing'); -env.config(); - const prepareServer = async () => { return new ApolloServer({ typeDefs, diff --git a/__tests__/washers.ts b/__tests__/washers.ts index b79c481..4d72623 100644 --- a/__tests__/washers.ts +++ b/__tests__/washers.ts @@ -1,3 +1,5 @@ +import * as env from 'dotenv'; +env.config(); import typeDefs from '../src/schema'; import resolvers from '../src/resolvers'; import { prisma } from '../src/generated/prisma-client'; diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 0eb6068..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: '3' -services: - pheonix: - build: . - ports: - - 4000:4000 - volumes: - - /usr/src/app - - /usr/src/app/node_modules - network_mode: "host" diff --git a/package-lock.json b/package-lock.json index 6c049fa..b9a3653 100644 --- a/package-lock.json +++ b/package-lock.json @@ -538,9 +538,9 @@ } }, "@types/body-parser": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.17.0.tgz", - "integrity": "sha512-a2+YeUjPkztKJu5aIF2yArYFQQp8d51wZ7DavSHjFuY1mqVgidGyzEQ41JIVNy82fXj8yPgy2vJmfIywgESW6w==", + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.17.1.tgz", + "integrity": "sha512-RoX2EZjMiFMjZh9lmYrwgoP9RTpAjSHiJxdp4oidAQVO02T7HER3xj9UKue5534ULWeqVEkujhWcyvUce+d68w==", "requires": { "@types/connect": "*", "@types/node": "*" @@ -562,10 +562,21 @@ "@types/node": "*" } }, + "@types/cookies": { + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/@types/cookies/-/cookies-0.7.4.tgz", + "integrity": "sha512-oTGtMzZZAVuEjTwCjIh8T8FrC8n/uwy+PG0yTvQcdZ7etoel7C7/3MSd7qrukENTgQtotG7gvBlBojuVs7X5rw==", + "requires": { + "@types/connect": "*", + "@types/express": "*", + "@types/keygrip": "*", + "@types/node": "*" + } + }, "@types/cors": { - "version": "2.8.5", - "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.5.tgz", - "integrity": "sha512-GmK8AKu8i+s+EChK/uZ5IbrXPcPaQKWaNSGevDT/7o3gFObwSUQwqb1jMqxuo+YPvj0ckGzINI+EO7EHcmJjKg==", + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-invOmosX0DqbpA+cE2yoHGUlF/blyf7nB0OGYBBiH27crcVm5NmFaZkLP4Ta1hGaesckCi5lVLlydNJCxkTOSg==", "requires": { "@types/express": "*" } @@ -576,9 +587,9 @@ "integrity": "sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==" }, "@types/express": { - "version": "4.17.0", - "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.0.tgz", - "integrity": "sha512-CjaMu57cjgjuZbh9DpkloeGxV45CnMGlVd+XpG7Gm9QgVrd7KFq+X4HY0vM+2v0bczS48Wg7bvnMY5TN+Xmcfw==", + "version": "4.17.1", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.1.tgz", + "integrity": "sha512-VfH/XCP0QbQk5B5puLqTLEeFgR8lfCJHZJKkInZ9mkYd+u8byX0kztXEQxEk4wZXJs8HI+7km2ALXjn4YKcX9w==", "requires": { "@types/body-parser": "*", "@types/express-serve-static-core": "*", @@ -586,9 +597,9 @@ } }, "@types/express-serve-static-core": { - "version": "4.16.7", - "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.16.7.tgz", - "integrity": "sha512-847KvL8Q1y3TtFLRTXcVakErLJQgdpFSaq+k043xefz9raEf0C7HalpSY7OW5PyjCnY8P7bPW5t/Co9qqp+USg==", + "version": "4.16.9", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.16.9.tgz", + "integrity": "sha512-GqpaVWR0DM8FnRUJYKlWgyARoBUAVfRIeVDZQKOttLFp5SmhhF9YFIYeTPwMd/AXfxlP7xVO2dj1fGu0Q+krKQ==", "requires": { "@types/node": "*", "@types/range-parser": "*" @@ -602,6 +613,40 @@ "@types/node": "*" } }, + "@types/fs-capacitor": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@types/fs-capacitor/-/fs-capacitor-2.0.0.tgz", + "integrity": "sha512-FKVPOCFbhCvZxpVAMhdBdTfVfXUpsh15wFHgqOKxh9N9vzWZVuWCSijZ5T4U34XYNnuj2oduh6xcs1i+LPI+BQ==", + "requires": { + "@types/node": "*" + } + }, + "@types/graphql-upload": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/@types/graphql-upload/-/graphql-upload-8.0.3.tgz", + "integrity": "sha512-hmLg9pCU/GmxBscg8GCr1vmSoEmbItNNxdD5YH2TJkXm//8atjwuprB+xJBK714JG1dkxbbhp5RHX+Pz1KsCMA==", + "requires": { + "@types/express": "*", + "@types/fs-capacitor": "*", + "@types/koa": "*", + "graphql": "^14.5.3" + }, + "dependencies": { + "graphql": { + "version": "14.5.8", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-14.5.8.tgz", + "integrity": "sha512-MMwmi0zlVLQKLdGiMfWkgQD7dY/TUKt4L+zgJ/aR0Howebod3aNgP5JkgvAULiR2HPVZaP2VEElqtdidHweLkg==", + "requires": { + "iterall": "^1.2.2" + } + } + } + }, + "@types/http-assert": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@types/http-assert/-/http-assert-1.5.1.tgz", + "integrity": "sha512-PGAK759pxyfXE78NbKxyfRcWYA/KwW17X290cNev/qAsn9eQIxkH4shoNBafH37wewhDG/0p1cHPbK6+SzZjWQ==" + }, "@types/istanbul-lib-coverage": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz", @@ -642,6 +687,32 @@ "integrity": "sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA==", "dev": true }, + "@types/keygrip": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@types/keygrip/-/keygrip-1.0.1.tgz", + "integrity": "sha1-/1QEYtL7TQqIRBzq8n0oewHD2Hg=" + }, + "@types/koa": { + "version": "2.0.50", + "resolved": "https://registry.npmjs.org/@types/koa/-/koa-2.0.50.tgz", + "integrity": "sha512-TcgOD2lh0EISSadAk1DOBYw7kNoY9XdeB3vEMOKiDDaTMYm+V54nyPsU7Ulb/htb5OBIR79RgTeCWntCcophLw==", + "requires": { + "@types/accepts": "*", + "@types/cookies": "*", + "@types/http-assert": "*", + "@types/keygrip": "*", + "@types/koa-compose": "*", + "@types/node": "*" + } + }, + "@types/koa-compose": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/@types/koa-compose/-/koa-compose-3.2.4.tgz", + "integrity": "sha512-ioou0rxkuWL+yBQYsHUQAzRTfVxAg8Y2VfMftU+Y3RA03/MzuFL0x/M2sXXj3PkfnENbHsjeHR1aMdezLYpTeA==", + "requires": { + "@types/koa": "*" + } + }, "@types/long": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.0.tgz", @@ -673,9 +744,9 @@ "integrity": "sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==" }, "@types/serve-static": { - "version": "1.13.2", - "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.2.tgz", - "integrity": "sha512-/BZ4QRLpH/bNYgZgwhKEh+5AsboDBcUdlBYgzoLX0fpj3Y2gp6EApyOlM3bK53wQS/OE1SrdSYBAbux2D1528Q==", + "version": "1.13.3", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.3.tgz", + "integrity": "sha512-oprSwp094zOglVrXdlo/4bAHtKTAxX6VT8FOZlBKrmyLbNvE1zxZyJ6yikMVtHIvwP45+ZQGJn+FdXGKTozq0g==", "requires": { "@types/express-serve-static-core": "*", "@types/mime": "*" @@ -920,6 +991,46 @@ "express": "^4.0.0", "graphql-subscriptions": "^1.0.0", "graphql-tools": "^4.0.0" + }, + "dependencies": { + "@types/body-parser": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.17.0.tgz", + "integrity": "sha512-a2+YeUjPkztKJu5aIF2yArYFQQp8d51wZ7DavSHjFuY1mqVgidGyzEQ41JIVNy82fXj8yPgy2vJmfIywgESW6w==", + "requires": { + "@types/connect": "*", + "@types/node": "*" + } + }, + "@types/express": { + "version": "4.17.0", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.0.tgz", + "integrity": "sha512-CjaMu57cjgjuZbh9DpkloeGxV45CnMGlVd+XpG7Gm9QgVrd7KFq+X4HY0vM+2v0bczS48Wg7bvnMY5TN+Xmcfw==", + "requires": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "*", + "@types/serve-static": "*" + } + }, + "apollo-server-express": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/apollo-server-express/-/apollo-server-express-2.6.9.tgz", + "integrity": "sha512-iTkdIdX7m9EAlmL/ZPkKR+x/xuFk1HYZWuJIJG57hHUhcOxj50u7F1E5+5fDwl5RFIdepQ61azF31hhNZuNi4g==", + "requires": { + "@apollographql/graphql-playground-html": "1.6.24", + "@types/accepts": "^1.3.5", + "@types/body-parser": "1.17.0", + "@types/cors": "^2.8.4", + "@types/express": "4.17.0", + "accepts": "^1.3.5", + "apollo-server-core": "2.6.9", + "body-parser": "^1.18.3", + "cors": "^2.8.4", + "graphql-subscriptions": "^1.0.0", + "graphql-tools": "^4.0.0", + "type-is": "^1.6.16" + } + } } }, "apollo-server-caching": { @@ -972,22 +1083,163 @@ "integrity": "sha512-errZvnh0vUQChecT7M4A/h94dnBSRL213dNxpM5ueMypaLYgnp4hiCTWIEaooo9E4yMGd1qA6WaNbLDG2+bjcg==" }, "apollo-server-express": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/apollo-server-express/-/apollo-server-express-2.6.9.tgz", - "integrity": "sha512-iTkdIdX7m9EAlmL/ZPkKR+x/xuFk1HYZWuJIJG57hHUhcOxj50u7F1E5+5fDwl5RFIdepQ61azF31hhNZuNi4g==", + "version": "2.9.5", + "resolved": "https://registry.npmjs.org/apollo-server-express/-/apollo-server-express-2.9.5.tgz", + "integrity": "sha512-6gonP7g5u2Kr+9cvKE+NuGPe+As7wRbz2yWoyLOym/TdXBmTRU4AKW2Qs+wpNanurzm2xbTa7sEfzrHGmembrQ==", "requires": { "@apollographql/graphql-playground-html": "1.6.24", "@types/accepts": "^1.3.5", - "@types/body-parser": "1.17.0", + "@types/body-parser": "1.17.1", "@types/cors": "^2.8.4", - "@types/express": "4.17.0", + "@types/express": "4.17.1", "accepts": "^1.3.5", - "apollo-server-core": "2.6.9", + "apollo-server-core": "^2.9.5", + "apollo-server-types": "^0.2.4", "body-parser": "^1.18.3", "cors": "^2.8.4", + "express": "^4.17.1", "graphql-subscriptions": "^1.0.0", "graphql-tools": "^4.0.0", + "parseurl": "^1.3.2", + "subscriptions-transport-ws": "^0.9.16", "type-is": "^1.6.16" + }, + "dependencies": { + "@apollographql/apollo-tools": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@apollographql/apollo-tools/-/apollo-tools-0.4.0.tgz", + "integrity": "sha512-7wEO+S+zgz/wVe3ilFQqICufRBYYDSNUkd1V03JWvXuSydbYq2SM5EgvWmFF+04iadt+aQ0XCCsRzCzRPQODfQ==", + "requires": { + "apollo-env": "0.5.1" + } + }, + "apollo-cache-control": { + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/apollo-cache-control/-/apollo-cache-control-0.8.4.tgz", + "integrity": "sha512-IZ1d3AXZtkZhLYo0kWqTbZ6nqLFaeUvLdMESs+9orMadBZ7mvzcAfBwrhKyCWPGeAAZ/jKv8FtYHybpchHgFAg==", + "requires": { + "apollo-server-env": "^2.4.3", + "graphql-extensions": "^0.10.3" + } + }, + "apollo-datasource": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/apollo-datasource/-/apollo-datasource-0.6.3.tgz", + "integrity": "sha512-gRYyFVpJgHE2hhS+VxMeOerxXQ/QYxWG7T6QddfugJWYAG9DRCl65e2b7txcGq2NP3r+O1iCm4GNwhRBDJbd8A==", + "requires": { + "apollo-server-caching": "^0.5.0", + "apollo-server-env": "^2.4.3" + } + }, + "apollo-engine-reporting": { + "version": "1.4.6", + "resolved": "https://registry.npmjs.org/apollo-engine-reporting/-/apollo-engine-reporting-1.4.6.tgz", + "integrity": "sha512-acfb7oFnru/8YQdY4x6+7WJbZfzdVETI8Cl+9ImgUrvUnE8P+f2SsGTKXTC1RuUvve4c56PAvaPgE+z8X1a1Mw==", + "requires": { + "apollo-engine-reporting-protobuf": "^0.4.0", + "apollo-graphql": "^0.3.3", + "apollo-server-caching": "^0.5.0", + "apollo-server-env": "^2.4.3", + "apollo-server-types": "^0.2.4", + "async-retry": "^1.2.1", + "graphql-extensions": "^0.10.3" + } + }, + "apollo-engine-reporting-protobuf": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/apollo-engine-reporting-protobuf/-/apollo-engine-reporting-protobuf-0.4.0.tgz", + "integrity": "sha512-cXHZSienkis8v4RhqB3YG3DkaksqLpcxApRLTpRMs7IXNozgV7CUPYGFyFBEra1ZFgUyHXx4G9MpelV+n2cCfA==", + "requires": { + "protobufjs": "^6.8.6" + } + }, + "apollo-server-caching": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/apollo-server-caching/-/apollo-server-caching-0.5.0.tgz", + "integrity": "sha512-l7ieNCGxUaUAVAAp600HjbUJxVaxjJygtPV0tPTe1Q3HkPy6LEWoY6mNHV7T268g1hxtPTxcdRu7WLsJrg7ufw==", + "requires": { + "lru-cache": "^5.0.0" + } + }, + "apollo-server-core": { + "version": "2.9.5", + "resolved": "https://registry.npmjs.org/apollo-server-core/-/apollo-server-core-2.9.5.tgz", + "integrity": "sha512-SlM/vhjhWb0ayXV3d4gnpq9gh2BsQj+UPfQXfq2X2KG9EH5I1JUH6EtlsctgMCZozirOZmEmUzlqZWSSUOUPgQ==", + "requires": { + "@apollographql/apollo-tools": "^0.4.0", + "@apollographql/graphql-playground-html": "1.6.24", + "@types/graphql-upload": "^8.0.0", + "@types/ws": "^6.0.0", + "apollo-cache-control": "^0.8.4", + "apollo-datasource": "^0.6.3", + "apollo-engine-reporting": "^1.4.6", + "apollo-server-caching": "^0.5.0", + "apollo-server-env": "^2.4.3", + "apollo-server-errors": "^2.3.3", + "apollo-server-plugin-base": "^0.6.4", + "apollo-server-types": "^0.2.4", + "apollo-tracing": "^0.8.4", + "fast-json-stable-stringify": "^2.0.0", + "graphql-extensions": "^0.10.3", + "graphql-tag": "^2.9.2", + "graphql-tools": "^4.0.0", + "graphql-upload": "^8.0.2", + "sha.js": "^2.4.11", + "subscriptions-transport-ws": "^0.9.11", + "ws": "^6.0.0" + } + }, + "apollo-server-env": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/apollo-server-env/-/apollo-server-env-2.4.3.tgz", + "integrity": "sha512-23R5Xo9OMYX0iyTu2/qT0EUb+AULCBriA9w8HDfMoChB8M+lFClqUkYtaTTHDfp6eoARLW8kDBhPOBavsvKAjA==", + "requires": { + "node-fetch": "^2.1.2", + "util.promisify": "^1.0.0" + } + }, + "apollo-server-errors": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/apollo-server-errors/-/apollo-server-errors-2.3.3.tgz", + "integrity": "sha512-MO4oJ129vuCcbqwr5ZwgxqGGiLz3hCyowz0bstUF7MR+vNGe4oe3DWajC9lv4CxrhcqUHQOeOPViOdIo1IxE3g==" + }, + "apollo-server-plugin-base": { + "version": "0.6.4", + "resolved": "https://registry.npmjs.org/apollo-server-plugin-base/-/apollo-server-plugin-base-0.6.4.tgz", + "integrity": "sha512-4rY+cBAIpQomGWYBtk8hHkLQWHrh5hgIBPQqmhXh00YFdcY+Ob1/cU2/2iqTcIzhtcaezsc8OZ63au6ahSBQqg==", + "requires": { + "apollo-server-types": "^0.2.4" + } + }, + "apollo-server-types": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/apollo-server-types/-/apollo-server-types-0.2.4.tgz", + "integrity": "sha512-G4FvBVgGQcTW6ZBS2+hvcDQkSfdOIKV+cHADduXA275v+5zl42g+bCaGd/hCCKTDRjmQvObLiMxH/BJ6pDMQgA==", + "requires": { + "apollo-engine-reporting-protobuf": "^0.4.0", + "apollo-server-caching": "^0.5.0", + "apollo-server-env": "^2.4.3" + } + }, + "apollo-tracing": { + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/apollo-tracing/-/apollo-tracing-0.8.4.tgz", + "integrity": "sha512-DjbFW0IvHicSlTVG+vK+1WINfBMRCdPPHJSW/j65JMir9Oe56WGeqL8qz8hptdUUmLYEb+azvcyyGsJsiR3zpQ==", + "requires": { + "apollo-server-env": "^2.4.3", + "graphql-extensions": "^0.10.3" + } + }, + "graphql-extensions": { + "version": "0.10.3", + "resolved": "https://registry.npmjs.org/graphql-extensions/-/graphql-extensions-0.10.3.tgz", + "integrity": "sha512-kwU0gUe+Qdfr8iZYT91qrPSwQNgPhB/ClF1m1LEPdxlptk5FhFmjpxAcbMZ8q7j0kjfnbp2IeV1OhRDCEPqz2w==", + "requires": { + "@apollographql/apollo-tools": "^0.4.0", + "apollo-server-env": "^2.4.3", + "apollo-server-types": "^0.2.4" + } + } } }, "apollo-server-plugin-base": { @@ -1731,9 +1983,9 @@ } }, "commander": { - "version": "2.20.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", - "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", + "version": "2.20.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.1.tgz", + "integrity": "sha512-cCuLsMhJeWQ/ZpsFTbE765kvVfoeSddc4nU3up4fV+fDBcfUXnbITJ+JzhkdjzOqhURjZgujxaioam4RM9yGUg==", "dev": true, "optional": true }, @@ -3301,9 +3553,9 @@ "dev": true }, "handlebars": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.2.tgz", - "integrity": "sha512-nvfrjqvt9xQ8Z/w0ijewdD/vvWDTOweBUm96NTr66Wfvo1mJenBLwcYmPs3TIBP5ruzYGD7Hx/DaM9RmhroGPw==", + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.2.tgz", + "integrity": "sha512-cIv17+GhL8pHHnRJzGu2wwcthL5sb8uDKBHvZ2Dtu5s1YNt0ljbzKbamnc+gr69y7bzwQiBdr5+hOpRd5pnOdg==", "dev": true, "requires": { "neo-async": "^2.6.0", diff --git a/package.json b/package.json index 703c491..b87b21c 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,11 @@ "dependencies": { "apollo-datasource-rest": "^0.5.1", "apollo-server": "^2.6.9", + "apollo-server-express": "^2.9.5", "dotenv": "^8.0.0", + "express": "^4.17.1", "graphql": "^14.4.2", + "jsonwebtoken": "^8.5.1", "pg": "^7.11.0", "prisma-client-lib": "^1.34.5" }, diff --git a/prisma/.env.sample b/prisma/.env.sample index 955ead9..e94fb4d 100644 --- a/prisma/.env.sample +++ b/prisma/.env.sample @@ -1,4 +1,5 @@ PRISMA_MANAGEMENT_API_SECRET= +PRISMA_HOST= PRISMA_SECRET= DB_HOST= DB_USER= diff --git a/prisma/docker-compose.yml b/prisma/docker-compose.yml index b0d096d..19f9035 100644 --- a/prisma/docker-compose.yml +++ b/prisma/docker-compose.yml @@ -4,11 +4,11 @@ services: image: prismagraphql/prisma:1.34 restart: always ports: - - "4466:4466" + - "4466:4466" environment: PRISMA_CONFIG: | - port: 4466 managementApiSecret: ${PRISMA_MANAGEMENT_API_SECRET} + port: 4466 databases: default: connector: postgres diff --git a/prisma/ecs-params.yml b/prisma/ecs-params.yml deleted file mode 100644 index 4da7146..0000000 --- a/prisma/ecs-params.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: 1 -task_definition: - task_execution_role: ecsTaskExecutionRole - ecs_network_mode: awsvpc - task_size: - mem_limit: 0.5GB - cpu_limit: 256 -run_params: - network_configuration: - awsvpc_configuration: - subnets: - - "subnet-011097e3140eb71a3" - - "subnet-0d1f6e25b3c1e7182" - assign_public_ip: ENABLED \ No newline at end of file diff --git a/prisma/prisma.yml b/prisma/prisma.yml index 339cbe3..d61989f 100644 --- a/prisma/prisma.yml +++ b/prisma/prisma.yml @@ -1,4 +1,4 @@ -endpoint: http://localhost:4466 +endpoint: ${env:PRISMA_HOST} datamodel: datamodel.prisma secret: ${env:PRISMA_SECRET} generate: diff --git a/src/datasources/society.ts b/src/datasources/society.ts deleted file mode 100644 index 4a1d8aa..0000000 --- a/src/datasources/society.ts +++ /dev/null @@ -1,23 +0,0 @@ -class Society { - private client: any; - constructor(pgClient){ - this.client = pgClient; - } - - async getSociety(id){ - const response = await this.client.query(`SELECT * FROM public.society WHERE name='${id}'`); - return response.rows[0] - } - - async getSocietyMembers(society, dataSources){ - console.log(society); - const members = society.members; - return await Promise.all(members.map(async (member) => { - const user = await dataSources.users.getUser(member); - console.log(user); - return user; - })); - } -} - -export default Society; \ No newline at end of file diff --git a/src/datasources/users.ts b/src/datasources/users.ts deleted file mode 100644 index 632f865..0000000 --- a/src/datasources/users.ts +++ /dev/null @@ -1,36 +0,0 @@ -class Users { - private pool:any; - private table:string; - - constructor(pool, table?:string) { - this.pool = pool; - this.table = table || 'public.user' - } - - async getUser(id) { - const response = await this.pool.query( - `SELECT * FROM ${this.table} WHERE username='${id}'`, - ); - return response.rows[0]; - } - - async getProp(id, prop) { - this.getUser(id).then(user => { - return user[prop]; - }); - } - - async addUser(newUser) { - const user = JSON.parse(JSON.stringify(newUser)); - const response = await this.pool.query( - `INSERT INTO ${this.table} ( - username, email, "imageUrl", phone, firstname, lastname, roomno) VALUES ( - $1::text, $2::text, $3::text, $4::text, $5::text, $6::text, $7::text) - returning username;`, - [user.username, user.email, user.imageUrl, user.phone, user.firstname, user.lastname, user.roomno], - ); - return user - } -} - -export default Users; diff --git a/src/datasources/washers.ts b/src/datasources/washers.ts deleted file mode 100644 index c876f32..0000000 --- a/src/datasources/washers.ts +++ /dev/null @@ -1,16 +0,0 @@ -class Washers{ - private pool; - private table; - constructor(pool, table?:string){ - this.pool = pool; - this.table = table || 'public.washers'; - } - - async getWasher(id:number){ - const query:string = `SELECT * FROM ${ this.table } WHERE id=${id}`; - const response = await this.pool.query(query); - return response.rows[0]; - } -} - -export default Washers \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 5c585ba..6649381 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,7 @@ -const {ApolloServer} = require("apollo-server"); +const {ApolloServer} = require("apollo-server-express"); +const express = require("express"); +const app = express(); + import * as env from "dotenv"; env.config(); import typeDefs from './schema'; @@ -13,6 +16,12 @@ const server = new ApolloServer({ }, } as any); -server.listen().then(async ({ url }) => { - console.log(`${url}`); +server.applyMiddleware({app}); + +app.get("/", (req, res) => { + res.send("OK").status(200); }); + +app.listen({port: 4000} , () => { + console.log("Server started at port 4000"); +}); \ No newline at end of file