graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Why is #headers called during #parse?

Open AndrewRayCode opened this issue 2 years ago • 0 comments

I'm trying to create a module where I can dynamically set the headers, so that I can toggle between admin/root level query authorization, and user bearer token based authorization.

In my module, I do something like this

HTTP = GraphQL::Client::HTTP.new(GraphqlGateway.gateway_url) do
    def headers(context)
      if context.try(:query_as_root_user)
        headers = {...}
      elsif context.try(:user_token)
        {'Authorization' => context[:user_token]}
      end
    end
  end

To my surprise, when I parse a query, I get the error undefined method each' for nil:NilClass`

I'm either misreading the error trace, or it appears #headers is being called during #parse - is this intentional? Shouldn't #parse produce some static data structure and not care about headers?

AndrewRayCode avatar Mar 01 '22 02:03 AndrewRayCode