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 statecodewise query #7

Closed
wants to merge 1 commit into from
Closed
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
98 changes: 64 additions & 34 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,82 @@ const {
GraphQLString,
GraphQLObjectType,
GraphQLList,
GraphQLInt
GraphQLInt,
} = require('graphql');


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

const StateCovidDataType = new GraphQLObjectType({
name: 'statewise',
fields: {
state: {
type: GraphQLString
type: GraphQLString,
},
active: {
type: GraphQLString
type: GraphQLString,
},
confirmed: {
type: GraphQLString
type: GraphQLString,
},
deaths: {
type: GraphQLString
type: GraphQLString,
},
recovered: {
type: GraphQLString
}
}
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
type: GraphQLString,
},
dailyconfirmed: {
type: GraphQLInt
type: GraphQLInt,
},
dailydeceased: {
type: GraphQLInt
type: GraphQLInt,
},
dailyrecovered: {
type: GraphQLInt
}
}
type: GraphQLInt,
},
},
});

/**
Expand All @@ -75,30 +92,43 @@ const RootQuery = new GraphQLObjectType({
total: {
type: CovidDataType,
async resolve() {
const data = await axios.get('https://api.covid19india.org/data.json')
.then(res => res.data.statewise[0]);
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));
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);
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,
});