Skip to content

Commit d34ec4b

Browse files
Merge pull request #17 from annkissam/feature/support-dynamic-client-http-token-and-urls
Update Client and HTTP caller to have dynamic config
2 parents 62c6ad7 + 4060ba8 commit d34ec4b

File tree

6 files changed

+46
-20
lines changed

6 files changed

+46
-20
lines changed

CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# Changelog
22

3-
## v.0.5.0
3+
## v0.6.0
4+
- [PR 17](https://github.com/annkissam/common_graphql_client/pull/17)
5+
Dynamic http api token and url support (Breaking change)
6+
7+
## v0.5.0
48
- [PR 15](https://github.com/annkissam/common_graphql_client/pull/15) Static Validation for query
59
on the client side using npm_graphql
610

7-
## v.0.3.3
11+
## v0.3.3
812
- [PR 13](`CommonGraphQLClient.Caller.Http.post\4`) Better HTTPoison error handling in `CommonGraphQLClient.Caller.Http.post\4`
913
- Allow http_opts to be sent to `CommonGraphQLClient.Caller.Http.post\4`
1014

11-
## v.0.3.2
15+
## v0.3.2
1216
- Fix UndefinedFunctionError error on Caller.Http.post & Caller.Nil.post
1317

14-
## v.0.3.1
18+
## v0.3.1
1519
- Add configurable timeout and error logging (https://github.com/annkissam/common_graphql_client/pull/9)
1620

1721
## v0.3.0

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ An Elixir libary for generating GraphQL clients. Adapters are provided for both
44

55
This library also supports client-side query validation using `nodejs`.
66

7+
## Contents
8+
9+
- [Documentation](#documentation)
10+
- [Installation](#Installation)
11+
- [Context](#Context)
12+
- [Client](#Client)
13+
- [Ecto Schemas](#Ecto-Schemas)
14+
- [GraphQL Queries](#GraphQL-Queries)
15+
- [GraphQL Subscriptions](#GraphQL-Subscriptions)
16+
- [Security](#Security)
17+
* [Client Security](#Client-Security)
18+
* [HTTP Server](#HTTP-Server)
19+
* [WebSocket Server](#WebSocket-Server)
20+
- [Client Query Validation](#Client-Query-Validation)
21+
* [Using NPM](#Using-Npm)
22+
* [Using Native Elixir](#Using-Native-Elixir)
23+
24+
725
## Documentation
826

927
Docs can be found at [https://hexdocs.pm/common_graphql_client](https://hexdocs.pm/common_graphql_client).
@@ -17,7 +35,7 @@ Add `common_graphql_client` to your list of dependencies in `mix.exs`:
1735
```elixir
1836
def deps do
1937
[
20-
{:common_graphql_client, "~> 0.1.0"},
38+
{:common_graphql_client, "~> 0.6.0"},
2139
{:httpoison, "~> 1.1"}, # If using HTTP queries
2240
{:absinthe_websocket, "~> 0.2.0"}, # If using WebSocket subscriptions (or WebSocket queries)
2341
]
@@ -261,7 +279,7 @@ end
261279

262280
## Security
263281

264-
### Client
282+
### Client Security
265283

266284
The HTTP Client can send `Bearer` tokens, whereas the WebSocket can send a token as a query param. Since these credentials should not be in source control, this library provides a way to set them at runtime. First, update the Mix config:
267285

@@ -379,7 +397,9 @@ defmodule MyAppWeb.UserSocket do
379397
end
380398
```
381399

382-
## Client-side Query Validation (using schema introspection result)
400+
## Client Query Validation
401+
402+
- (using schema introspection result)
383403

384404
Query validation can be done at the client-side using schema introspection
385405
result to get closer to real integration tests without having to run a graphql
@@ -416,13 +436,13 @@ to be available (which is for most of the phoenix development environment)
416436
For more information on this check out the documentation and examples for
417437
[`CommonGraphqlClient.StaticValidator.NpmGraphql`](https://hexdocs.pm/common_graphql_client/CommonGraphQLClient.StaticValidator.NpmGraphql.html#content)
418438

419-
### Using npm-graphql
439+
### Using Npm
420440

421441
This uses `npm` and `node` commands to run schema validation. Make sure you
422442
have `npm` and `node` installed.
423443

424444

425-
### Using native elixir
445+
### Using Native Elixir
426446

427447
This strategy will use native elixir for performing the validation.
428448
This is work in progress

lib/common_graphql_client/caller/http.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ if Code.ensure_loaded?(HTTPoison) do
1414
|> Poison.encode!()
1515

1616
case HTTPoison.post(
17-
client.http_api_url(),
17+
client.http_api_url(opts),
1818
body,
1919
[
2020
{"Content-Type", "application/json"},
21-
{"authorization", "Bearer #{client.http_api_token()}"}
21+
{"authorization", "Bearer #{client.http_api_token(opts)}"}
2222
],
2323
Keyword.get(opts, :http_opts, [])
2424
) do

lib/common_graphql_client/caller/websocket.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ if Code.ensure_loaded?(AbsintheWebSocket) do
3131
{AbsintheWebSocket.Supervisor,
3232
[
3333
subscriber: client.mod(),
34-
url: client.websocket_api_url(),
35-
token: client.websocket_api_token(),
34+
url: client.websocket_api_url(opts),
35+
token: client.websocket_api_token(opts),
3636
base_name: base_name,
3737
async: Keyword.get(opts, :async, true)
3838
]}

lib/common_graphql_client/client.ex

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,19 @@ defmodule CommonGraphQLClient.Client do
7272
end
7373
end
7474

75-
def http_api_token do
75+
def http_api_token(_opts \\ []) do
7676
config(:http_api_token)
7777
end
7878

79-
def http_api_url do
79+
def http_api_url(_opts \\ []) do
8080
config(:http_api_url)
8181
end
8282

83-
def websocket_api_token do
83+
def websocket_api_token(_opts \\ []) do
8484
config(:websocket_api_token)
8585
end
8686

87-
def websocket_api_url do
87+
def websocket_api_url(_opts \\ []) do
8888
config(:websocket_api_url)
8989
end
9090

@@ -235,8 +235,10 @@ defmodule CommonGraphQLClient.Client do
235235
defoverridable handle: 2,
236236
handle: 3,
237237
handle_subscribe_to: 2,
238-
http_api_token: 0,
239-
websocket_api_token: 0
238+
http_api_token: 1,
239+
http_api_url: 1,
240+
websocket_api_token: 1,
241+
websocket_api_url: 1
240242
end
241243
end
242244
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule CommonGraphqlClient.MixProject do
22
use Mix.Project
33

4-
@version "0.5.0"
4+
@version "0.6.0"
55
@url "https://github.com/annkissam/common_graphql_client"
66
@maintainers [
77
"Josh Adams",

0 commit comments

Comments
 (0)