`fetch': key not found: "data" (KeyError) : graphql-client error

Viewed 2217

I was trying to use the graphql query within ruby to fetch github repositories. Before writing the query, I was working on getting the graphql-client working. I'm facing issues with graphql client.

I was following this link for graphql client: https://github.com/github/graphql-client

require 'graphql'
require 'graphql/client'
require 'graphql/client/http'

module MyGraphQL
  HTTP = GraphQL::Client::HTTP.new('https://github.com/graphql') do
    def client_context
      { access_token: 'xxxxxxxxxxxxxxxxxx' }
    end

    def headers(_context)
      client_context
    end
  end

  Schema = GraphQL::Client.load_schema(HTTP)

  Client = GraphQL::Client.new(schema: Schema, execute: HTTP)
end

I'm getting the following errors in a terminal:

    'fetch': key not found: "data" (KeyError)
    'load'
    'load_schema'
    'load_schema'
2 Answers

Also faced with same problem. Replacing body method to this helped:

    def headers(context)
      {
        "Authorization" => "bearer #{TOKEN}"
      }
    end

Where is the TOKEN is the Personal access token gotten from here: https://github.com/settings/tokens

Related