Last active
October 24, 2020 15:52
Star
You must be signed in to star a gist
Adding the statewise resource
This file contains 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
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 } | |
); |
This file contains 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
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