Or use the context that you pass into the headers method.
require"graphql/client"require"graphql/client/http"# Star Wars API example wrappermoduleSWAPI# Configure GraphQL endpoint using the basic HTTP network adapter.HTTP=GraphQL::Client::HTTP.new("https://example.com/graphql")dodefheaders(context){"X-Api-Key"=>context[:api_key]}endendend
And when you perform a query on your GraphQL client, pass in the context:
storefront_api_key="dynamic api key"result=SWAPI::Client.query(SWAPI::MyQuery,variables: {},context: {api_key: storefront_api_key})
So everytime you perform a query, you have the opportunity to pass in a context to alter your headers.
dfritsch86 commentedApr 23, 2019
I need to dynamically change the request headers. How to accomplish this?
The text was updated successfully, but these errors were encountered: