Your IP : 216.73.216.220


Current Path : /home/deltalab/PMS/ims-connector/graphql/schema/
Upload File :
Current File : //home/deltalab/PMS/ims-connector/graphql/schema/order.schema.js

// RESOURCES =========================================
const orderAdapter = require('../../logic/shopify/order');
const { orderTC } = require('../types/order.type');

// RESOLVERS =========================================
/**
 * OrderMany query
 * Get all the orders
 * @param {Int} limit the maximum number of orders to retrieve
 * @param {Int} offset the items to skip
 * @return a list of orders
 */
orderTC.addResolver(
  {
    kind: 'query',
    name: 'orderMany',
    type: [orderTC],
    args: {
      limit: 'Int',
      offset: 'Int',
    },
    resolve: async (rp) => {
      // Retrieve orders from shopify
      console.log('contacting order adapter for orders');
      // TODO: add webhook support
      // TODO: use limit and offset to reduce query size
      const orders = await orderAdapter.getOrders();
      // Return the orders straight away
      console.log(`returning ${orders.length} orders`);
      return orders;
    },
  },
);

/**
 * OrderOne query
 * Get a single order with the specified id
 */
orderTC.addResolver(
  {
    kind: 'query',
    name: 'orderById',
    type: orderTC,
    args: {
      orderId: 'String',
    },
    resolve: async (_, { orderId }) => {
      const order = await orderAdapter.getOrder(orderId);
      return order;
    },
  },
);

// QUERIES ===========================================
const orderQuery = {
  orderMany: orderTC.getResolver('orderMany'),
  orderById: orderTC.getResolver('orderById'),
};

const orderMutation = {
  // intentionally empty
};

// EXPORTS ===========================================
module.exports = {
  orderQuery,
  orderMutation,
};