This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default { | |
| async fetch(request, env) { | |
| switch (request.method) { | |
| case 'HEAD': | |
| case 'GET': | |
| const url = new URL(request.url); | |
| const key = decodeURIComponent(url.pathname); | |
| // replace suffix / after concating cause raw key still needed for regex | |
| let objKey = key.replace(/\/+$/gm, ''); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // resolvers.ts | |
| // ...other codes | |
| export default { | |
| // ...other codes | |
| Merchant: { | |
| products({id: merchantId}: Merchant, {pagination: input}: {pagination: IPagination}, {loaders}: IGraphQLSchemaContext) { | |
| const paginationCollector = { | |
| limit: input?.limit || 10, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // graphql.ts | |
| // ...other codes | |
| const loaders = () => { | |
| return { | |
| // ...other loaders | |
| getProductsByMerchantId(pagination: IPagination){ | |
| const {limit, offset, orderBy, sortBy, search} = pagination; | |
| return new Dataloader(async merchantIds => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // graphql.ts | |
| // ...other codes | |
| enum PaginationSortByEnum { | |
| ASC = 'asc', | |
| DESC = 'desc' | |
| } | |
| interface IPagination { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #typeDefs.graphql | |
| type Query{ | |
| allMerchants: [Merchant!]! | |
| } | |
| type Merchant { | |
| id: ID! | |
| name: String! | |
| products(pagination: PaginationInput!): [Product!]! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // resolvers.ts | |
| import Knex from 'knex'; | |
| import {IGraphQLSchemaContext, Merchant} from '../../types'; | |
| export default { | |
| Query: { | |
| allMerchants() { | |
| return Knex(config.get('database'))('merchants'); | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // graphql.ts | |
| import 'graphql-import-node'; | |
| import {makeExecutableSchema} from 'graphql-tools'; | |
| import {ApolloServer} from 'apollo-server-express'; | |
| import Knex from 'knex'; | |
| import Dataloader from 'dataloader'; | |
| import config from 'config'; | |
| import resolvers from './resolvers'; | |
| import * as typeDefs from './typeDefs.graphql'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #typeDefs.graphql | |
| type Query{ | |
| allMerchants: [Merchant!]! | |
| } | |
| type Merchant { | |
| id: ID! | |
| name: String! | |
| products: [Product!]! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const router = require('express').Router(); | |
| const { Product } = require('../models/') | |
| router.post('order', (req, res) => { | |
| try { | |
| let outOfStock = { | |
| bool: false, | |
| data: [] | |
| } | |
| let allProduct = await Product.findAll({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const router = require('express').Router() | |
| const kue = require('kue') | |
| const queue = kue.createQueue() | |
| queue.process('order', async (job, done) => { | |
| try { | |
| let outOfStock = { | |
| bool: false, | |
| data: [], | |
| } |
NewerOlder