Небольшая проблема с использованием GraphQl - PullRequest
0 голосов
/ 04 октября 2018

Я новичок в 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
   }
 }

. Вот моя схема.Очевидно, что это имеет какое-то отношение к полям, но я пробовал довольно много вещей и не понял этого.Кроме того, как лучше всего передать аргументы вызову 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,
})
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...