I have been working on setting up a GraphQL application to access data from games.espn.com. However, I am facing an issue where my queries are returning null values. I suspect that there may be something missing in terms of return or resolve functions in the code. Despite spending several days reviewing the code, I cannot pinpoint why the desired value is not being returned.
Below is a snippet from my schema.js file:
const {
GraphQLObjectType,
GraphQLString,
GraphQLInt,
GraphQLSchema,
GraphQLList,
GraphQLNonNull,
GraphQLBoolean,
GraphQLFloat
} = require('graphql');
const axios = require('axios');
const request = require('request');
// Define various GraphQL object types for different data structures like Player, Slots, Team, etc.
...
// The BoxscoreType defines the structure of the box score data and includes information about teams, scoring period ID, and home team bonus.
const BoxscoreType = new GraphQLObjectType({
name: 'Boxscore',
fields: () => ({
teams: {
type: TeamsType,
},
scoringPeriodId: {
type: GraphQLInt,
},
matchupPeriodId: {
type: GraphQLInt,
},
homeTeamBonus: {
type: GraphQLInt,
}
})
});
// More GraphQL object types defined here...
// The EspnQuery represents the query structure for retrieving ESPN box score data based on specific parameters.
const EspnQuery = new GraphQLObjectType({
name: 'EspnQuery',
fields: {
getBoxscore: {
type: BoxscoreDataType,
args: {
leagueId: {
name: 'leagueId',
type: new GraphQLNonNull(GraphQLInt)
},
seasonId: {
name: 'seasonId',
type: new GraphQLNonNull(GraphQLInt)
},
teamId: {
name: 'teamId',
type: new GraphQLNonNull(GraphQLInt)
},
scoringPeriodId: {
name: 'scoringPeriodId',
type: new GraphQLNonNull(GraphQLInt)
},
},
resolve: (obj, {leagueId, seasonId, teamId, scoringPeriodId}) => {
// Logic to fetch data from the ESPN API using Axios library
}
}
},
});
// Lastly, export the GraphQL schema with EspnQuery as the root query.
module.exports = new GraphQLSchema({
query: EspnQuery
});
When executing the following query in Graphiql:
{
getBoxscore(leagueId: 1150587, seasonId: 2017, teamId: 5, scoringPeriodId: 7) {
boxscore{
teams {
list0{
slots{
player0{
player{
firstName
}
}
}
}
}
}
}
}
The resulting output is:
{
"data": {
"getBoxscore": {
"boxscore": {
"teams": {
"list0": null
}
}
}
}
}