我是GraphQL的新手,并且在graphiql上遇到此错误
{
"errors": [
{
"message": "The type of Weather.main must be Output Type but got:
undefined.\n\nThe type of Weather.weather must be Output Type but got:
undefined."
}
]
} `
这就是我在graphiql中运行的
{
weatherData{
main{
temp
humidity
}
weather{
description
icon
}
dt_txt
}
}
这是我的架构。显然与该领域有关,但是我已经尝试了很多事情并且没有弄清楚。另外,将args传递给axios调用以从特定纬度和经度获取数据的最佳方法是什么?帮助将不胜感激!谢谢你。
`const axios = require('axios');
const {
GraphQLBoolean,
GraphQLInt,
GraphQLString,
GraphQLObjectType,
GraphQLFloat,
GraphQLNonNull,
GraphQLSchema,
GraphQLList
} = require('graphql');
const WeatherType = new GraphQLObjectType({
name: "Weather",
fields: () => {
return {
main: {
temp: {type: GraphQLFloat},
resolve: (main) => {
return main.temp
},
humidity: {type: GraphQLFloat},
resolve: (main) => {
return main.humidity
}
},
weather: {
description: {type: GraphQLString},
resolve: (weather) => {
return weather.description
},
icon: {type: GraphQLString},
resolve: (weather) => {
return weather.icon
}
},
dt_txt: {type: GraphQLString}
}
}
})
const Query = new GraphQLObjectType ({
name: "Query",
fields: () => {
return {
weatherData: {
type: new GraphQLList(WeatherType),
resolve: () => {
return
axios.get(`http://api.openweathermap.org/data/2.5/forecast?
lat=33.4484&lon=112.0740&APPID={APIKEY}&units=impe
rial`).then(response => {
console.log('response.data: ', response.data.list);
return response.data.list[0]
})
}
}
}
}
})
module.exports = new GraphQLSchema({
query: Query,
})