Apollo Server - как получить дополнительную информацию о журналах - PullRequest
0 голосов
/ 03 августа 2020

Я использую площадку GraphQL для тестирования запроса и получаю следующий ответ:

{
  "errors": [
    {
      "message": "Request failed with status code 400",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "currentPrices"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "config": {
            "url": "https://api.coindesk.com/v1/bpi/currentprice.json",
            "method": "get",
            "headers": {
              "Accept": "application/json, text/plain, */*",
              "User-Agent": "axios/0.19.2",
              "host": "jsonplaceholder.typicode.com"
            },
            "transformRequest": [
              null
            ],
            "transformResponse": [
              null
            ],
            "timeout": 0,
            "xsrfCookieName": "XSRF-TOKEN",
            "xsrfHeaderName": "X-XSRF-TOKEN",
            "maxContentLength": -1
          }
        }
      }
    }
  ],
  "data": {
    "currentPrices": null
  }
}

Ошибка сообщает мне, что это ошибка сервера и, как следствие, не имеет ничего общего с моим схема. Когда я смотрю на инструменты разработчика в Chrome и вижу это как полезную нагрузку моего запроса, он выглядит нормально:

enter image description here

The query I paste into GraphQL Playground is this:

{
  currentPrices{
    title
  }
}

I'm not sure what I'm doing wrong. I tried another API and it throws the same error. I am behind a corporate proxy but I'm not sure if that has anything to do with this. I did try using the global-agent package and setting environment variables for proxy but that doesn't seem to fix it. Thanks for any helpful tips.

Here are my schemas for context:

const { gql } = require('apollo-server');

const typeDefs = gql`
  scalar JSON

  type Query {
    currentPrices: BitcoinPrice
  }

  type Time {
    updated: String
    updatedISO: String
    updateduk: String
  }

  type USD {
    code: String
    symbol: String
    rate: String
    description: String
    rate_float: Float
  }

  type GBP {
    code: String
    symbol: String
    rate: String
    description: String
    rate_float: Float
  }

  type EUR {
    code: String
    symbol: String
    rate: String
    description: String
    rate_float: Float
  }

  type Bpi {
    usd: USD
    gbp: GBP
    eur: EUR
  }

  type BitcoinPrice {
    time: Time
    disclaimer: String
    chartName: String
    bpi: Bpi
  }
`;

module.exports = typeDefs;

And here's the endpoint I'm hitting:

введите описание изображения здесь

Это определенно проблема с HTTP-запросом, потому что, когда я жестко кодирую данные в резолвере и возвращаю их, все работает хорошо.

...