Реагирует apollo [Ошибка GraphQL]: Сообщение: не удалось запросить поле «запрос» типа «RootQueryType» - PullRequest
0 голосов
/ 26 марта 2020

Мне нужна помощь, пожалуйста.

У меня есть этот компонент в root -dir / client / src / components

import React from "react";
import { useQuery } from "@apollo/react-hooks";
import { gql } from "apollo-boost";

const LAUNCHES_QUERY = gql`
  {
    query
    LaunchesQuery {
      launches {
        flight_number
        mission_name
        launch_date_local
        launch_success
      }
    }
  }
`;

function Launches() {
  const { loading, error, data } = useQuery(LAUNCHES_QUERY);

  if (loading) return <h4>Loading...</h4>;
  if (error) return <h4>Ooopss! Error :(</h4>; // * Hitting this when page loads
  console.log(data);

  return (
    <div>
      <h2>Works!</h2>
    </div>
  );
}

export default Launches;

, который получает данные из этого файл в root -dir / server / gqlschema. js

// Creating our Root Query here where we can have endpoints that resolve our data
const RootQuery = new GraphQLObjectType({
  name: "RootQueryType",
  fields: {
    // Get a list of launches
    launches: {
      type: new GraphQLList(LaunchType),
      resolve(parent, args) {
        return axios
          .get("https://api.spacexdata.com/v3/launches")
          .then(res => res.data);
      }
    },
    // Get a single launch
    launch: {
      type: LaunchType,
      args: {
        flight_number: { type: GraphQLInt }
      },
      resolve(parent, args) {
        return axios
          .get(`https://api.spacexdata.com/v3/launches/${args.flight_number}`)
          .then(res => res.data);
      }
    },
    // Get a list of rockets
    rockets: {
      type: new GraphQLList(RocketType),
      resolve(parent, args) {
        return axios
          .get("https://api.spacexdata.com/v3/rockets")
          .then(res => res.data);
      }
    },
    // Get a single rocket
    rocket: {
      type: RocketType,
      args: {
        id: { type: GraphQLString }
      },
      resolve(parent, args) {
        return axios
          .get(`https://api.spacexdata.com/v3/rockets/${args.id}`)
          .then(res => res.data);
      }
    }
  }
});

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

, но когда я загружаю браузер, я сталкиваюсь с ошибкой (см. * для справки) и вижу следующее в моей консоли

[GraphQL error]: Message: Cannot query field "query" on type "RootQueryType"., Location: [object Object], Path: undefined
[GraphQL error]: Message: Cannot query field "LaunchesQuery" on type "RootQueryType". Did you mean "launches"?, Location: [object Object], Path: undefined
[Network error]: ServerError: Response not successful: Received status code 400

Есть идеи, почему я получаю эту ошибку, а не записываю консоль каких-либо данных?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...