Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Last active October 24, 2020 15:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save YonatanKra/e4ab900af340d17dd84e99f0d603ce95 to your computer and use it in GitHub Desktop.
Adding the statewise resource
import askql from "askql";
import {values} from '../resources/index.js';
import middlewareFactory from "askql/askExpressMiddleware/askExpressMiddleware.js";
import { customResources } from "./statewise.js";
const { askExpressMiddleware } = middlewareFactory;
const { resources } = askql;
export const askMiddleware = askExpressMiddleware(
{ resources: {...resources, ...customResources}, values },
{ callNext: true, passError: true }
);
import askql from 'askql';
import fetch from 'node-fetch';
const { askvm } = askql;
export const customResources = {
statewise: askvm.resource({
resolver: async () => {
const res = await fetch('https://api.covid19india.org/data.json');
const fullData = await res.json();
const dataSet = fullData.statewise.splice(1);
return dataSet.map(({ state, active, confirmed, deaths, recovered }) => ({
state,
active,
confirmed,
deaths,
recovered,
}));
},
}),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment