Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added query to retreive state data #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 134 additions & 84 deletions src/schema.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,154 @@
const axios = require('axios').default;
const axios = require("axios").default;

const {
GraphQLSchema,
GraphQLString,
GraphQLObjectType,
GraphQLList,
GraphQLInt
} = require('graphql');
GraphQLSchema,

GraphQLString,

GraphQLObjectType,

GraphQLList,

GraphQLInt,
} = require("graphql");

const CovidDataType = new GraphQLObjectType({
name: 'CovidStats',
fields: () => ({
active: {
type: GraphQLInt
},
confirmed: {
type: GraphQLString
},
deaths: {
type: GraphQLString
},
recovered: {
type: GraphQLString
}
})
name: "CovidStats",
fields: () => ({
active: {
type: GraphQLInt,
},

confirmed: {
type: GraphQLString,
},

deaths: {
type: GraphQLString,
},

recovered: {
type: GraphQLString,
},
}),
});

const StateCovidDataType = new GraphQLObjectType({
name: 'statewise',
fields: {
state: {
type: GraphQLString
},
active: {
type: GraphQLString
},
confirmed: {
type: GraphQLString
},
deaths: {
type: GraphQLString
},
recovered: {
type: GraphQLString
}
}
name: "statewise",
fields: {
state: {
type: GraphQLString,
},

active: {
type: GraphQLString,
},

confirmed: {
type: GraphQLString,
},

deaths: {
type: GraphQLString,
},

recovered: {
type: GraphQLString,
},
},
});

const StatecodewiseCovidDataType = new GraphQLObjectType({
name: "statecodewise",
fields: {
statecode: {
type: GraphQLString,
},

active: {
type: GraphQLString,
},

confirmed: {
type: GraphQLString,
},

deaths: {
type: GraphQLString,
},
},
});

const DailyCovidDataType = new GraphQLObjectType({
name: 'daily',
fields: {
date: {
type: GraphQLString
},
dailyconfirmed: {
type: GraphQLInt
},
dailydeceased: {
type: GraphQLInt
},
dailyrecovered: {
type: GraphQLInt
}
}
name: "daily",
fields: {
date: {
type: GraphQLString,
},

dailyconfirmed: {
type: GraphQLInt,
},

dailydeceased: {
type: GraphQLInt,
},

dailyrecovered: {
type: GraphQLInt,
},
},
});

/**
* Total data
*/
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
total: {
type: CovidDataType,
async resolve() {
const data = await axios.get('https://api.covid19india.org/data.json')
.then(res => res.data.statewise[0]);
return data;
}
},
statewise: {
type: new GraphQLList(StateCovidDataType),
async resolve() {
const data = await axios.get('https://api.covid19india.org/data.json')
.then(res => res.data.statewise.splice(1));
return data;
}
},
datewise: {
type: new GraphQLList(DailyCovidDataType),
async resolve() {
const data = await axios.get('https://api.covid19india.org/data.json')
.then(res => res.data.cases_time_series);
return data;
}
}
}
name: "RootQueryType",

fields: {
total: {
type: CovidDataType,
async resolve() {
const data = await axios
.get("https://api.covid19india.org/data.json")
.then((res) => res.data.statewise[0]);
return data;
},
},

statewise: {
type: new GraphQLList(StateCovidDataType),
async resolve() {
const data = await axios
.get("https://api.covid19india.org/data.json")
.then((res) => res.data.statewise.splice(1));
return data;
},
},

datewise: {
type: new GraphQLList(DailyCovidDataType),
async resolve() {
const data = await axios
.get("https://api.covid19india.org/data.json")
.then((res) => res.data.cases_time_series);
return data;
},
},

statecodewise: {
type: new GraphQLList(StatecodewiseCovidDataType),
async resolve() {
const data = await axios
.get("https://api.covid19india.org/data.json")
.then((res) => res.data.statewise.splice(1));
return data;
},
},
},
});

module.exports = new GraphQLSchema({
query: RootQuery
});
query: RootQuery,
});