Skip to content

Instantly share code, notes, and snippets.

@YonatanKra

YonatanKra/askql.js

Last active Oct 24, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.