move to vercel now function api structure
I haven't really tested the API yet, because it's hard to query GraphQL directly, but I'll set up the client in a bit for it!
This commit is contained in:
parent
8f4ed8e10d
commit
81a2306667
37 changed files with 792 additions and 5403 deletions
2
app/.gitignore → .gitignore
vendored
2
app/.gitignore → .gitignore
vendored
|
@ -1,3 +1,5 @@
|
||||||
|
.env
|
||||||
|
|
||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
11
.now/README.txt
Normal file
11
.now/README.txt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
> Why do I have a folder named ".now" in my project?
|
||||||
|
The ".now" folder is created when you link a directory to a ZEIT Now project.
|
||||||
|
|
||||||
|
> What does the "project.json" file contain?
|
||||||
|
The "project.json" file contains:
|
||||||
|
- The ID of the ZEIT Now project that you linked ("projectId")
|
||||||
|
- The ID of the user or team your ZEIT Now project is owned by ("orgId")
|
||||||
|
|
||||||
|
> Should I commit the ".now" folder?
|
||||||
|
No, you should not share the ".now" folder with anyone.
|
||||||
|
Upon creation, it will be automatically added to your ".gitignore" file.
|
1
.now/project.json
Normal file
1
.now/project.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"projectId":"QmXjZr2uCGd6WHQTpf2twqzaJw6nU5jP3SMBR5wSLU2kno","orgId":"IzHHT7MV4cSD5XalfZxPpnnw"}
|
10
api/graphql.js
Normal file
10
api/graphql.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
const express = require("express");
|
||||||
|
const { ApolloServer } = require("apollo-server-express");
|
||||||
|
|
||||||
|
const { config } = require("../src/server");
|
||||||
|
|
||||||
|
const server = new ApolloServer(config);
|
||||||
|
const app = express();
|
||||||
|
server.applyMiddleware({ app });
|
||||||
|
|
||||||
|
module.exports = app;
|
|
@ -9,7 +9,13 @@
|
||||||
"@testing-library/jest-dom": "^4.2.4",
|
"@testing-library/jest-dom": "^4.2.4",
|
||||||
"@testing-library/react": "^9.3.2",
|
"@testing-library/react": "^9.3.2",
|
||||||
"@testing-library/user-event": "^7.1.2",
|
"@testing-library/user-event": "^7.1.2",
|
||||||
|
"apollo-server": "^2.12.0",
|
||||||
|
"apollo-server-express": "^2.12.0",
|
||||||
|
"dataloader": "^2.0.0",
|
||||||
"emotion-theming": "^10.0.27",
|
"emotion-theming": "^10.0.27",
|
||||||
|
"express": "^4.17.1",
|
||||||
|
"graphql": "^15.0.0",
|
||||||
|
"mysql2": "^2.1.0",
|
||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
"react-scripts": "3.4.1"
|
"react-scripts": "3.4.1"
|
||||||
|
@ -36,6 +42,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"apollo-server-testing": "^2.12.0",
|
||||||
"prettier": "^2.0.5"
|
"prettier": "^2.0.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
119
server/.gitignore
vendored
119
server/.gitignore
vendored
|
@ -1,119 +0,0 @@
|
||||||
.env
|
|
||||||
|
|
||||||
# From https://github.com/github/gitignore/blob/2a4de265d37eca626309d8e115218d18985b5435/Node.gitignore
|
|
||||||
|
|
||||||
# Logs
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
lerna-debug.log*
|
|
||||||
|
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
||||||
|
|
||||||
# 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
|
|
||||||
*.lcov
|
|
||||||
|
|
||||||
# nyc test coverage
|
|
||||||
.nyc_output
|
|
||||||
|
|
||||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
||||||
.grunt
|
|
||||||
|
|
||||||
# Bower dependency directory (https://bower.io/)
|
|
||||||
bower_components
|
|
||||||
|
|
||||||
# node-waf configuration
|
|
||||||
.lock-wscript
|
|
||||||
|
|
||||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
||||||
build/Release
|
|
||||||
|
|
||||||
# Dependency directories
|
|
||||||
node_modules/
|
|
||||||
jspm_packages/
|
|
||||||
|
|
||||||
# Snowpack dependency directory (https://snowpack.dev/)
|
|
||||||
web_modules/
|
|
||||||
|
|
||||||
# TypeScript cache
|
|
||||||
*.tsbuildinfo
|
|
||||||
|
|
||||||
# Optional npm cache directory
|
|
||||||
.npm
|
|
||||||
|
|
||||||
# Optional eslint cache
|
|
||||||
.eslintcache
|
|
||||||
|
|
||||||
# Microbundle cache
|
|
||||||
.rpt2_cache/
|
|
||||||
.rts2_cache_cjs/
|
|
||||||
.rts2_cache_es/
|
|
||||||
.rts2_cache_umd/
|
|
||||||
|
|
||||||
# Optional REPL history
|
|
||||||
.node_repl_history
|
|
||||||
|
|
||||||
# Output of 'npm pack'
|
|
||||||
*.tgz
|
|
||||||
|
|
||||||
# Yarn Integrity file
|
|
||||||
.yarn-integrity
|
|
||||||
|
|
||||||
# dotenv environment variables file
|
|
||||||
.env
|
|
||||||
.env.test
|
|
||||||
|
|
||||||
# parcel-bundler cache (https://parceljs.org/)
|
|
||||||
.cache
|
|
||||||
.parcel-cache
|
|
||||||
|
|
||||||
# Next.js build output
|
|
||||||
.next
|
|
||||||
|
|
||||||
# Nuxt.js build / generate output
|
|
||||||
.nuxt
|
|
||||||
dist
|
|
||||||
|
|
||||||
# Gatsby files
|
|
||||||
.cache/
|
|
||||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
||||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
||||||
# public
|
|
||||||
|
|
||||||
# vuepress build output
|
|
||||||
.vuepress/dist
|
|
||||||
|
|
||||||
# Serverless directories
|
|
||||||
.serverless/
|
|
||||||
|
|
||||||
# FuseBox cache
|
|
||||||
.fusebox/
|
|
||||||
|
|
||||||
# DynamoDB Local files
|
|
||||||
.dynamodb/
|
|
||||||
|
|
||||||
# TernJS port file
|
|
||||||
.tern-port
|
|
||||||
|
|
||||||
# Stores VSCode versions used for testing VSCode extensions
|
|
||||||
.vscode-test
|
|
||||||
|
|
||||||
# yarn v2
|
|
||||||
|
|
||||||
.yarn/cache
|
|
||||||
.yarn/unplugged
|
|
||||||
.yarn/build-state.yml
|
|
||||||
.pnp.*
|
|
|
@ -1,26 +0,0 @@
|
||||||
{
|
|
||||||
"name": "impress-2020-server",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"main": "index.js",
|
|
||||||
"author": "Matchu",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"apollo-server": "^2.12.0",
|
|
||||||
"dataloader": "^2.0.0",
|
|
||||||
"dotenv": "^8.2.0",
|
|
||||||
"graphql": "^15.0.0",
|
|
||||||
"mysql2": "^2.1.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"apollo-server-testing": "^2.12.0",
|
|
||||||
"jest": "^25.4.0",
|
|
||||||
"nodemon": "^2.0.3",
|
|
||||||
"prettier": "^2.0.5"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"start": "node index.js",
|
|
||||||
"watch": "nodemon index.js",
|
|
||||||
"test": "jest",
|
|
||||||
"setup-mysql-user": "mysql -h impress.openneo.net -u matchu -p < setup-mysql-user.sql"
|
|
||||||
}
|
|
||||||
}
|
|
5224
server/yarn.lock
5224
server/yarn.lock
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,10 @@
|
||||||
require("dotenv").config();
|
|
||||||
const mysql = require("mysql2/promise");
|
const mysql = require("mysql2/promise");
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
process.env["IMPRESS_MYSQL_USER"],
|
||||||
|
process.env["IMPRESS_MYSQL_PASSWORD"]
|
||||||
|
);
|
||||||
|
|
||||||
async function connectToDb() {
|
async function connectToDb() {
|
||||||
const db = await mysql.createConnection({
|
const db = await mysql.createConnection({
|
||||||
host: "impress.openneo.net",
|
host: "impress.openneo.net",
|
|
@ -1,4 +1,4 @@
|
||||||
const { ApolloServer, gql } = require("apollo-server");
|
const { gql } = require("apollo-server");
|
||||||
|
|
||||||
const connectToDb = require("./db");
|
const connectToDb = require("./db");
|
||||||
const { loadItems, buildItemTranslationLoader } = require("./loaders");
|
const { loadItems, buildItemTranslationLoader } = require("./loaders");
|
||||||
|
@ -26,7 +26,7 @@ const resolvers = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const server = new ApolloServer({
|
const config = {
|
||||||
typeDefs,
|
typeDefs,
|
||||||
resolvers,
|
resolvers,
|
||||||
context: async () => {
|
context: async () => {
|
||||||
|
@ -36,12 +36,14 @@ const server = new ApolloServer({
|
||||||
itemTranslationLoader: buildItemTranslationLoader(db),
|
itemTranslationLoader: buildItemTranslationLoader(db),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
|
const { ApolloServer } = require("apollo-server");
|
||||||
|
const server = new ApolloServer(config);
|
||||||
server.listen().then(({ url }) => {
|
server.listen().then(({ url }) => {
|
||||||
console.log(`🚀 Server ready at ${url}`);
|
console.log(`🚀 Server ready at ${url}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { server };
|
module.exports = { config };
|
|
@ -1,18 +1,18 @@
|
||||||
const gql = require("graphql-tag");
|
const gql = require("graphql-tag");
|
||||||
|
const { ApolloServer } = require("apollo-server");
|
||||||
const { createTestClient } = require("apollo-server-testing");
|
const { createTestClient } = require("apollo-server-testing");
|
||||||
|
|
||||||
const connectToDb = require("./db");
|
const connectToDb = require("./db");
|
||||||
const actualConnectToDb = jest.requireActual("./db");
|
const actualConnectToDb = jest.requireActual("./db");
|
||||||
const { server } = require("./index");
|
const { config } = require("./index");
|
||||||
|
|
||||||
const { query } = createTestClient(server);
|
const { query } = createTestClient(new ApolloServer(config));
|
||||||
|
|
||||||
// Spy on db.execute, so we can snapshot the queries we run. This can help us
|
// Spy on db.execute, so we can snapshot the queries we run. This can help us
|
||||||
// keep an eye on perf - watch for tests with way too many queries!
|
// keep an eye on perf - watch for tests with way too many queries!
|
||||||
jest.mock("./db");
|
jest.mock("./db");
|
||||||
let queryFn;
|
let queryFn;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
numQueries = 0;
|
|
||||||
connectToDb.mockImplementation(async (...args) => {
|
connectToDb.mockImplementation(async (...args) => {
|
||||||
const db = await actualConnectToDb(...args);
|
const db = await actualConnectToDb(...args);
|
||||||
queryFn = jest.spyOn(db, "execute");
|
queryFn = jest.spyOn(db, "execute");
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue