Working version
This commit is contained in:
@@ -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