Working version
This commit is contained in:
Generated
+18
@@ -3227,6 +3227,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"knex-stringcase": {
|
||||
"version": "1.4.5",
|
||||
"resolved": "https://registry.npmjs.org/knex-stringcase/-/knex-stringcase-1.4.5.tgz",
|
||||
"integrity": "sha512-dO8CzBAfxX6HeZ6BP+5KCMn3450MRoz3xsUascogE3OucUIyv/ki/W30YQz15EuAbHr03s9DfgiNlKfAvD+PvQ==",
|
||||
"requires": {
|
||||
"stringcase": "^4.3.1"
|
||||
}
|
||||
},
|
||||
"knex-tiny-logger": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/knex-tiny-logger/-/knex-tiny-logger-2.1.0.tgz",
|
||||
@@ -4633,6 +4641,11 @@
|
||||
"safe-buffer": "~5.2.0"
|
||||
}
|
||||
},
|
||||
"stringcase": {
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/stringcase/-/stringcase-4.3.1.tgz",
|
||||
"integrity": "sha512-Ov7McNX1sFaEX9NWijD1hIOVDDhKdnFzN9tvoa1N8xgrclouhsO4kBPVrTPhjO/zP5mn1Ww03uZ2SThNMXS7zg=="
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
|
||||
@@ -5089,6 +5102,11 @@
|
||||
"homedir-polyfill": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"validator": {
|
||||
"version": "13.5.2",
|
||||
"resolved": "https://registry.npmjs.org/validator/-/validator-13.5.2.tgz",
|
||||
"integrity": "sha512-mD45p0rvHVBlY2Zuy3F3ESIe1h5X58GPfAtslBjY7EtTqGquZTj+VX/J4RnHWN8FKq0C9WRVt1oWAcytWRuYLQ=="
|
||||
},
|
||||
"vary": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
||||
|
||||
+3
-1
@@ -15,12 +15,14 @@
|
||||
"datasource-sql": "^1.4.0",
|
||||
"dotenv": "^8.2.0",
|
||||
"graphql": "^15.5.0",
|
||||
"knex-stringcase": "^1.4.5",
|
||||
"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"
|
||||
"typescript": "^4.2.3",
|
||||
"validator": "^13.5.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^4.21.0",
|
||||
|
||||
@@ -26,7 +26,7 @@ interface Order {
|
||||
exchangeRate: number;
|
||||
exchangeRateEur: number;
|
||||
invoiceId: string;
|
||||
contractCustomerId: number;
|
||||
contractCustomerId: number | null;
|
||||
vatNumber: string;
|
||||
comment: string;
|
||||
cancelsOrderId: number;
|
||||
@@ -71,15 +71,12 @@ export class OrderAPI extends SQLDataSource {
|
||||
];
|
||||
}
|
||||
|
||||
async getOrder(id: number) {
|
||||
const data = await this.knex
|
||||
async getOrder(id: number): Promise<Order> {
|
||||
return await this.knex
|
||||
.select('*')
|
||||
.from('orders')
|
||||
.where('id', id)
|
||||
.first()
|
||||
.cache(MINUTE);
|
||||
|
||||
console.log(data);
|
||||
|
||||
return { id: 2, countryCode: 'DK' };
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -2,16 +2,18 @@ import dotenv from 'dotenv';
|
||||
dotenv.config();
|
||||
|
||||
import { ApolloServer } from 'apollo-server';
|
||||
|
||||
import knexStringcase from 'knex-stringcase';
|
||||
import { dbConfig } from './config';
|
||||
import { typeDefs } from './schema';
|
||||
import resolvers from './resolvers';
|
||||
|
||||
import { OrderAPI } from './datasources/order';
|
||||
|
||||
const knexConfig = knexStringcase(dbConfig);
|
||||
|
||||
// set up any dataSources our resolvers need
|
||||
const dataSources = () => ({
|
||||
orderApi: new OrderAPI(dbConfig),
|
||||
orderApi: new OrderAPI(knexConfig),
|
||||
});
|
||||
|
||||
const context = async ({ req }) => {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { GraphQLScalarType } from 'graphql';
|
||||
import { Kind } from 'graphql/language';
|
||||
|
||||
export const DateTimeScalar = new GraphQLScalarType({
|
||||
name: 'DateTime',
|
||||
description: 'Date custom scalar type',
|
||||
parseValue(value) {
|
||||
return new Date(value); // value from the client
|
||||
},
|
||||
serialize(value) {
|
||||
return new Date(value).toISOString(); // value sent to the client
|
||||
},
|
||||
parseLiteral(ast) {
|
||||
if (ast.kind === Kind.INT) {
|
||||
return parseInt(ast.value, 10); // ast value is always in string format
|
||||
}
|
||||
return null;
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
import orders from './order';
|
||||
import { DateTimeScalar } from './datetime-type';
|
||||
|
||||
const resolvers = {
|
||||
Query: { ...orders },
|
||||
DateTime: DateTimeScalar,
|
||||
};
|
||||
|
||||
export default resolvers;
|
||||
@@ -4,8 +4,4 @@ const orders = {
|
||||
order: (_, { id }, { dataSources }) => dataSources.orderApi.getOrder(id),
|
||||
};
|
||||
|
||||
const resolvers = {
|
||||
Query: { ...orders },
|
||||
};
|
||||
|
||||
export default resolvers;
|
||||
export default orders;
|
||||
@@ -1,6 +1,8 @@
|
||||
import { gql } from 'apollo-server';
|
||||
|
||||
const typeDefs = gql`
|
||||
scalar DateTime
|
||||
|
||||
type Query {
|
||||
orders: [Order]
|
||||
order(id: ID!): Order
|
||||
@@ -8,7 +10,51 @@ const typeDefs = gql`
|
||||
|
||||
type Order {
|
||||
id: ID!
|
||||
inserted: DateTime
|
||||
paid: Boolean
|
||||
confirmed: Boolean
|
||||
delivered: Boolean
|
||||
newsletter: Boolean
|
||||
creditInvoice: Boolean
|
||||
canceled: Boolean
|
||||
reminder: Boolean
|
||||
deliveredDate: DateTime
|
||||
countryCode: String
|
||||
language: String
|
||||
deliveryCountryCode: String
|
||||
deliveryMethod: String
|
||||
deliveryPrice: String
|
||||
deliveryVat: Float
|
||||
customerType: String
|
||||
paymentType: String
|
||||
attention: String
|
||||
currency: String
|
||||
exchangeRate: Float
|
||||
exchangeRateEur: Float
|
||||
invoiceId: String
|
||||
contractCustomerId: Int
|
||||
vatNumber: String
|
||||
comment: String
|
||||
cancelsOrderId: Int
|
||||
cancelledByOrderId: Int
|
||||
orderlogId: Int
|
||||
resellerStore: String
|
||||
orderSum: Float
|
||||
klarnaOrderId: String
|
||||
pwintyId: Int
|
||||
email: String
|
||||
phone: String
|
||||
deliveryEmail: String
|
||||
deliveryPhone: String
|
||||
customerFirstname: String
|
||||
customerLastname: String
|
||||
customerEmail: String
|
||||
customerCellphone: String
|
||||
billingAddressId: Int
|
||||
deliveryAddressId: Int
|
||||
flyer_ids: String
|
||||
market: String
|
||||
locale: String
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user