WIP
This commit is contained in:
@@ -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 };
|
||||
Reference in New Issue
Block a user