Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ datocms_api_key = Application.fetch_env!(:my_app, :api_key)
DatoCMS.GraphQLClient.configure(api_key: datocms_api_key)
```

# Environments
If you've multiple DatoCMS environment you can control which one we'll fetch data from by using the :environment keyword.
Example:
```elixir
datocms_api_key = Application.fetch_env!(:my_app, :api_key)
DatoCMS.GraphQLClient.configure(api_key: datocms_api_key, environment: "stage")
```

# Queries

* single items: `DatoCMS.GraphQLClient.fetch!(:foo, "{ bar }").bar`,
Expand Down
6 changes: 6 additions & 0 deletions lib/datocms/graphql_client/backends/standard_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ defmodule DatoCMS.GraphQLClient.Backends.StandardClient do
Neuron.Config.set(headers: [authorization: "Bearer #{api_key}"])
end

if Keyword.has_key?(config, :environment) do
headers = Neuron.Config.get(:headers)
environment = config[:environment]
Neuron.Config.set(headers: headers ++ ["X-Environment": "#{environment}"])
end

Neuron.Config.set(connection_opts: [timeout: :infinity, recv_timeout: :infinity])
Neuron.Config.set(parse_options: [keys: :atoms])
end
Expand Down