WIP
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
DATABASE_URL=postgresql://fondberg:@docker.for.mac.localhost/photowall
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"parserOptions": {
|
||||||
|
"sourceType": "module",
|
||||||
|
"ecmaVersion": 2017
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"es6": true
|
||||||
|
},
|
||||||
|
"extends": ["prettier"],
|
||||||
|
"plugins": ["@typescript-eslint", "prettier"],
|
||||||
|
"rules": {
|
||||||
|
"prettier/prettier": ["error"]
|
||||||
|
}
|
||||||
|
}
|
||||||
+92
@@ -0,0 +1,92 @@
|
|||||||
|
### ts build
|
||||||
|
build/
|
||||||
|
|
||||||
|
dist
|
||||||
|
package.zip
|
||||||
|
|
||||||
|
### https://raw.github.com/github/gitignore/49d13cdba39774f7fa224ef13f4a1153200e2710/Global/macOS.gitignore
|
||||||
|
|
||||||
|
*.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
|
||||||
|
### https://raw.github.com/github/gitignore/49d13cdba39774f7fa224ef13f4a1153200e2710/Node.gitignore
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.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
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules
|
||||||
|
jspm_packages
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# serverless
|
||||||
|
.serverless
|
||||||
|
|
||||||
|
*.sublime-project
|
||||||
|
*.sublime-workspace
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"trailingComma": "all",
|
||||||
|
"singleQuote": true
|
||||||
|
}
|
||||||
Generated
+5191
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"name": "graphql-server-pw",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "nodemon -w src --ext ts --exec ts-node src/index.ts"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"apollo-datasource": "^0.8.0",
|
||||||
|
"apollo-datasource-rest": "^0.11.0",
|
||||||
|
"apollo-server": "^2.22.2",
|
||||||
|
"datasource-sql": "^1.4.0",
|
||||||
|
"dotenv": "^8.2.0",
|
||||||
|
"graphql": "^15.5.0",
|
||||||
|
"nodemon": "^2.0.7",
|
||||||
|
"pg": "^8.5.1",
|
||||||
|
"pg-hstore": "^2.3.3",
|
||||||
|
"prettier": "^2.2.1",
|
||||||
|
"ts-node": "^9.1.1",
|
||||||
|
"typescript": "^4.2.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@typescript-eslint/eslint-plugin": "^4.21.0",
|
||||||
|
"@typescript-eslint/parser": "^4.21.0",
|
||||||
|
"eslint": "^7.23.0",
|
||||||
|
"eslint-config-prettier": "^8.1.0",
|
||||||
|
"eslint-plugin-prettier": "^3.3.1"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"testPathIgnorePatterns": [
|
||||||
|
"/node_modules/",
|
||||||
|
"/__utils"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
export const dbConfig = {
|
||||||
|
client: 'pg',
|
||||||
|
connection: 'postgresql://fondberg:@docker.for.mac.localhost/photowall',
|
||||||
|
pool: {
|
||||||
|
min: 1,
|
||||||
|
max: 10,
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
import { SQLDataSource } from 'datasource-sql';
|
||||||
|
|
||||||
|
const MINUTE = 60;
|
||||||
|
|
||||||
|
interface Order {
|
||||||
|
id: number;
|
||||||
|
inserted: Date;
|
||||||
|
paid: boolean;
|
||||||
|
confirmed: boolean;
|
||||||
|
delivered: boolean;
|
||||||
|
newsletter: boolean;
|
||||||
|
creditInvoice: boolean;
|
||||||
|
canceled: boolean;
|
||||||
|
reminder: boolean;
|
||||||
|
deliveredDate: Date;
|
||||||
|
countryCode: string;
|
||||||
|
language: string;
|
||||||
|
deliveryCountryCode: string;
|
||||||
|
deliveryMethod: string;
|
||||||
|
deliveryPrice: string;
|
||||||
|
deliveryVat: number;
|
||||||
|
customerType: string;
|
||||||
|
paymentType: string;
|
||||||
|
attention: string;
|
||||||
|
currency: string;
|
||||||
|
exchangeRate: number;
|
||||||
|
exchangeRateEur: number;
|
||||||
|
invoiceId: string;
|
||||||
|
contractCustomerId: number;
|
||||||
|
vatNumber: string;
|
||||||
|
comment: string;
|
||||||
|
cancelsOrderId: number;
|
||||||
|
cancelledByOrderId: number;
|
||||||
|
orderlogId: number;
|
||||||
|
resellerStore: string;
|
||||||
|
orderSum: number;
|
||||||
|
klarnaOrderId: string;
|
||||||
|
pwintyId: number;
|
||||||
|
email: string;
|
||||||
|
phone: string;
|
||||||
|
deliveryEmail: string;
|
||||||
|
deliveryPhone: string;
|
||||||
|
customerFirstname: string;
|
||||||
|
customerLastname: string;
|
||||||
|
customerEmail: string;
|
||||||
|
customerCellphone: string;
|
||||||
|
billingAddressId: number;
|
||||||
|
deliveryAddressId: number;
|
||||||
|
flyer_ids: string;
|
||||||
|
market: string;
|
||||||
|
locale: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class OrderAPI extends SQLDataSource {
|
||||||
|
constructor(config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getOrders() {
|
||||||
|
const data = await this.knex
|
||||||
|
.select('*')
|
||||||
|
.from('orders')
|
||||||
|
.where('inserted', '>=', '2021-03-01T00:00:00Z')
|
||||||
|
.cache(MINUTE);
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
return [
|
||||||
|
{ id: 1, countryCode: 'SE' },
|
||||||
|
{ id: 2, countryCode: 'DK' },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
async getOrder(id: number) {
|
||||||
|
const data = await this.knex
|
||||||
|
.select('*')
|
||||||
|
.from('orders')
|
||||||
|
.where('id', id)
|
||||||
|
.cache(MINUTE);
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
return { id: 2, countryCode: 'DK' };
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import dotenv from 'dotenv';
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
import { ApolloServer } from 'apollo-server';
|
||||||
|
|
||||||
|
import { dbConfig } from './config';
|
||||||
|
import { typeDefs } from './schema';
|
||||||
|
import resolvers from './resolvers';
|
||||||
|
|
||||||
|
import { OrderAPI } from './datasources/order';
|
||||||
|
|
||||||
|
// set up any dataSources our resolvers need
|
||||||
|
const dataSources = () => ({
|
||||||
|
orderApi: new OrderAPI(dbConfig),
|
||||||
|
});
|
||||||
|
|
||||||
|
const context = async ({ req }) => {
|
||||||
|
return { data: { foo: 'bar' } };
|
||||||
|
};
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const server = new ApolloServer({
|
||||||
|
typeDefs,
|
||||||
|
resolvers,
|
||||||
|
dataSources,
|
||||||
|
context,
|
||||||
|
introspection: true,
|
||||||
|
playground: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.listen();
|
||||||
|
|
||||||
|
console.log('Server is running on http://localhost:4000');
|
||||||
|
}
|
||||||
|
main();
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// (parent, args, ctx, info)
|
||||||
|
const orders = {
|
||||||
|
orders: (_, __, { dataSources }) => dataSources.orderApi.getOrders(),
|
||||||
|
order: (_, { id }, { dataSources }) => dataSources.orderApi.getOrder(id),
|
||||||
|
};
|
||||||
|
|
||||||
|
const resolvers = {
|
||||||
|
Query: { ...orders },
|
||||||
|
};
|
||||||
|
|
||||||
|
export default resolvers;
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { gql } from 'apollo-server';
|
||||||
|
|
||||||
|
const typeDefs = gql`
|
||||||
|
type Query {
|
||||||
|
orders: [Order]
|
||||||
|
order(id: ID!): Order
|
||||||
|
}
|
||||||
|
|
||||||
|
type Order {
|
||||||
|
id: ID!
|
||||||
|
countryCode: String
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export { typeDefs };
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es2020",
|
||||||
|
"module": "commonjs",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"strictPropertyInitialization": false,
|
||||||
|
"allowJs": true
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user