Skip to content

Commit 1e14a3b

Browse files
authored
Merge pull request #25 from ospaarmann/downgrade_poison
Downgrade poison and test against Dgraph v1.0.13
2 parents 53cf4a7 + dc5f249 commit 1e14a3b

File tree

6 files changed

+35
-134
lines changed

6 files changed

+35
-134
lines changed

Changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [0.2.0-beta.2] - 2019-03-28
10+
11+
- Downgrade poison to `v3.1.0`.
12+
- Test against Dgraph `v1.0.13`
13+
- Set the GRPC deadline and `DBConnection` checkout timeout to use `:timeout` (contribution by @emhagman).
14+
- Update dependency `uuid` to `elixir_uuid` (contribution by @emhagman)
15+
- Some smaller tweaks (contribution by @optikfluffel).
16+
- Update the docs.
17+
918
## [0.2.0-beta.1] - 2019-01-22
1019

1120
- Handle `:gun_up` and `:gun_down` messages as debug level for now.

README.md

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**ExDgraph is functional but I would be careful using it in production. If you want to help, please drop me a message. Any help is greatly appreciated!**
44

5-
ExDgraph is a gRPC based client for the [Dgraph](https://github.com/dgraph-io/dgraph) database. It uses the [DBConnection](https://hexdocs.pm/db_connection/DBConnection.html) behaviour to support transactions and connection pooling via [Poolboy](https://github.com/devinus/poolboy). Works with Dgraph v1.0.11 (latest).
5+
ExDgraph is a gRPC based client for the [Dgraph](https://github.com/dgraph-io/dgraph) database. It uses the [DBConnection](https://hexdocs.pm/db_connection/DBConnection.html) behaviour to support transactions and connection pooling via [Poolboy](https://github.com/devinus/poolboy). Works with Dgraph v1.0.13 (latest).
66

77
> Dgraph is an open source, horizontally scalable and distributed graph database, providing ACID transactions, consistent replication and linearizable reads. [...] Dgraph's goal is to provide Google production level scale and throughput, with low enough latency to be serving real time user queries, over terabytes of structured data. ([Source](https://github.com/dgraph-io/dgraph))
88
@@ -27,7 +27,7 @@ Add the package `ex_dgraph` to your list of dependencies in `mix.exs`:
2727
```elixir
2828
def deps do
2929
[
30-
{:ex_dgraph, "~> 0.2.0-beta.1"}
30+
{:ex_dgraph, "~> 0.2.0-beta.2"}
3131
]
3232
end
3333
```
@@ -82,13 +82,13 @@ def start(_type, _args) do
8282
end
8383
```
8484

85-
**Important:** Please also note the instructions further down on how to run ExDgraph with Phoenix 1.3. It requires Cowboy 2 which means you have to change some things.
86-
8785
## Usage
8886

89-
Again, this is work in progress. I'll add more examples on how to use this on the go. So far you can connect to a server and run a simple query. I recommend installing and running Dgraph locally with Docker. You find information on how to do that [here](https://docs.dgraph.io/get-started/#from-docker-image). To use this simple example you first have to [import the example data](https://docs.dgraph.io/get-started/#step-3-run-queries). You can just open [http://localhost:8000](http://localhost:8000) in your browser when Dgraph is running to execute and visualize queries using Ratel.
87+
I recommend installing and running Dgraph locally with Docker. You find information on how to do that [here](https://docs.dgraph.io/get-started/#from-docker-image). To use this simple example you first have to [import the example data](https://docs.dgraph.io/get-started/#step-3-run-queries). You can just open [http://localhost:8000](http://localhost:8000) in your browser when Dgraph is running to execute and visualize queries using Ratel.
88+
89+
At the moment simple queries, mutations and operations are supported. And to make things easier ExDgraph returns an Elixir map and you can also just insert a map. This allows you to insert a complex dataset with vertices and edges in one call. To make things even better: If there is a `uid` present anywhere in the map the record isn't inserted but updated. This way you can update and add records in one go.
9090

91-
At the moment simple queries, mutations and operations are supported via the DBConnection behaviour. Everything else is done directly via the Protobuf API. This will change. Check the tests for examples.
91+
Also check the tests for more examples.
9292

9393
**Example for a query**
9494

@@ -266,6 +266,8 @@ ExDgraph.operation(conn, %{schema: @testing_schema})
266266

267267
**Example for a raw query**
268268

269+
This is an example on how to use the Protobuf API with GRPC directly and how to extend the library.
270+
269271
```elixir
270272
# Connect to Server
271273
{:ok, channel} = GRPC.Stub.connect("#localhost:9080")
@@ -296,63 +298,8 @@ request = ExDgraph.Api.Request.new(query: query)
296298
json = Poison.decode!(msg.json)
297299
```
298300

299-
## Using with Phoenix 1.3
300-
Since grpc-elixir needs Cowboy 2 you need to upgrade your Phoenix app to work with Cowboy 2.
301-
302-
**Update dependencies in your mix.exs**
303-
304-
Open up the mix.exs file and replace the dependencies with this:
305-
306-
```elixir
307-
defp deps do
308-
[
309-
{:phoenix, git: "https://github.com/phoenixframework/phoenix", branch: "master", override: true},
310-
{:plug, git: "https://github.com/elixir-plug/plug", branch: "master", override: true},
311-
{:phoenix_pubsub, "~> 1.0"},
312-
{:phoenix_html, "~> 2.10"},
313-
{:phoenix_live_reload, "~> 1.0", only: :dev},
314-
{:gettext, "~> 0.11"},
315-
{:cowboy, "~> 2.1", override: true},
316-
{:ex_dgraph, github: "ospaarmann/exdgraph", tag: "v0.1.0"}
317-
]
318-
end
319-
```
320-
321-
Run `mix deps.get` to retrieve the new dependencies.
322-
323-
**Create a self-signed certificate for https**
324-
325-
We will need to do this as, although http2 does not specifically require it, browser do expect http2 connections to be secured over TLS.
326-
327-
In your project folder run:
328-
329-
```
330-
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout priv/server.key -out priv/server.pem
331-
```
332-
333-
Add the two generated files to .gitignore.
334-
335-
Now we will need to adjust the Endpoint configuration to use a secure connection and use a Cowboy 2 handler
336-
337-
Replace the configuration with the following.
338-
339-
```elixir
340-
config :my_app, MyAppWeb.Endpoint,
341-
debug_errors: true,
342-
handler: Phoenix.Endpoint.Cowboy2Handler,
343-
code_reloader: true,
344-
check_origin: false,
345-
watchers: [],
346-
https: [port: 4000, keyfile: "priv/server.key", certfile: "priv/server.pem"]
347-
```
348-
349-
This tells phoenix to listen on port 4000 with the just generated certificate. Furthermore, the handler tells Phoenix to use Cowboy2.
350-
351-
If you now start the application with `mix phx.server` and go to https://localhost:4000 the browser will tell that the connection is not secure with for example NET::ERR_CERT_AUTHORITY_INVALID. This is because the certificate is self signed, and not by a certificate authority. You can open the certificate in for example Keychain on Mac OS X and tell your OS to trust the certificate.
352-
353-
*[Source](https://maartenvanvliet.nl/2017/12/15/upgrading_phoenix_to_http2/)*
354-
355301
## Using SSL
302+
356303
If you want to connect to Dgraph using SSL you have to set the `:ssl` config to `true` and provide a certificate:
357304

358305
```elixir

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3.2"
22
services:
33
zero:
4-
image: dgraph/dgraph:v1.0.11
4+
image: dgraph/dgraph:v1.0.13
55
volumes:
66
- type: bind
77
source: ./dgraph_data
@@ -14,7 +14,7 @@ services:
1414
restart: on-failure
1515
command: dgraph zero --my=zero:5080
1616
server:
17-
image: dgraph/dgraph:v1.0.11
17+
image: dgraph/dgraph:v1.0.13
1818
volumes:
1919
- type: bind
2020
source: ./dgraph_data
@@ -27,7 +27,7 @@ services:
2727
restart: on-failure
2828
command: dgraph alpha --my=server:7080 --lru_mb=2048 --zero=zero:5080
2929
ratel:
30-
image: dgraph/dgraph:v1.0.11
30+
image: dgraph/dgraph:v1.0.13
3131
volumes:
3232
- type: bind
3333
source: ./dgraph_data

lib/exdgraph.ex

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule ExDgraph do
22
@moduledoc """
3-
ExDgraph is a gRPC based client for the Dgraph database. It uses the DBConnection behaviour to support transactions and connection pooling via Poolboy. Works with Dgraph v1.0.11 (latest).
3+
ExDgraph is a gRPC based client for the Dgraph database. It uses the DBConnection behaviour to support transactions and connection pooling via Poolboy. Works with Dgraph v1.0.13 (latest).
44
55
## Installation
66
@@ -9,7 +9,7 @@ defmodule ExDgraph do
99
```elixir
1010
def deps do
1111
[
12-
{:ex_dgraph, "~> 0.2.0-beta.1"}
12+
{:ex_dgraph, "~> 0.2.0-beta.2"}
1313
]
1414
end
1515
```
@@ -84,13 +84,13 @@ defmodule ExDgraph do
8484
end
8585
```
8686
87-
**Important:** Please also note the instructions further down on how to run ExDgraph with Phoenix 1.3. It requires Cowboy 2 which means you have to change some things.
88-
8987
## Usage
9088
91-
Again, this is work in progress. I'll add more examples on how to use this on the go. So far you can connect to a server and run a simple query. I recommend installing and running Dgraph locally with Docker. You find information on how to do that [here](https://docs.dgraph.io/get-started/#from-docker-image). To use this simple example you first have to [import the example data](https://docs.dgraph.io/get-started/#step-3-run-queries). You can just open [http://localhost:8000](http://localhost:8000) in your browser when Dgraph is running to execute and visualize queries using Ratel.
89+
I recommend installing and running Dgraph locally with Docker. You find information on how to do that [here](https://docs.dgraph.io/get-started/#from-docker-image). To use this simple example you first have to [import the example data](https://docs.dgraph.io/get-started/#step-3-run-queries). You can just open [http://localhost:8000](http://localhost:8000) in your browser when Dgraph is running to execute and visualize queries using Ratel.
90+
91+
At the moment simple queries, mutations and operations are supported. And to make things easier ExDgraph returns an Elixir map and you can also just insert a map. This allows you to insert a complex dataset with vertices and edges in one call. To make things even better: If there is a `uid` present anywhere in the map the record isn't inserted but updated. This way you can update and add records in one go.
9292
93-
At the moment simple queries, mutations and operations are supported via the DBConnection behaviour. Everything else is done directly via the Protobuf API. This will change. Check the tests for examples.
93+
Also check the tests for more examples.
9494
9595
### Example for a query
9696
@@ -268,6 +268,8 @@ defmodule ExDgraph do
268268
269269
### Example for a raw query
270270
271+
This is an example on how to use the Protobuf API with GRPC directly and how to extend the library.
272+
271273
```elixir
272274
# Connect to Server
273275
{:ok, channel} = GRPC.Stub.connect("#localhost:9080")
@@ -298,63 +300,8 @@ defmodule ExDgraph do
298300
json = Poison.decode!(msg.json)
299301
```
300302
301-
## Using with Phoenix 1.3
302-
Since grpc-elixir needs Cowboy 2 you need to upgrade your Phoenix app to work with Cowboy 2.
303-
304-
### Update dependencies in your mix.exs
305-
306-
Open up the mix.exs file and replace the dependencies with this:
307-
308-
```elixir
309-
defp deps do
310-
[
311-
{:phoenix, git: "https://github.com/phoenixframework/phoenix", branch: "master", override: true},
312-
{:plug, git: "https://github.com/elixir-plug/plug", branch: "master", override: true},
313-
{:phoenix_pubsub, "~> 1.0"},
314-
{:phoenix_html, "~> 2.10"},
315-
{:phoenix_live_reload, "~> 1.0", only: :dev},
316-
{:gettext, "~> 0.11"},
317-
{:cowboy, "~> 2.1", override: true},
318-
{:ex_dgraph, "~> 0.1.0", github: "ospaarmann/exdgraph", branch: "master"}
319-
]
320-
end
321-
```
322-
323-
Run `mix deps.get` to retrieve the new dependencies.
324-
325-
### Create a self-signed certificate for https
326-
327-
We will need to do this as, although http2 does not specifically require it, browser do expect http2 connections to be secured over TLS.
328-
329-
In your project folder run:
330-
331-
```
332-
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout priv/server.key -out priv/server.pem
333-
```
334-
335-
Add the two generated files to .gitignore.
336-
337-
Now we will need to adjust the Endpoint configuration to use a secure connection and use a Cowboy 2 handler
338-
339-
Replace the configuration with the following.
340-
341-
```elixir
342-
config :my_app, MyAppWeb.Endpoint,
343-
debug_errors: true,
344-
handler: Phoenix.Endpoint.Cowboy2Handler,
345-
code_reloader: true,
346-
check_origin: false,
347-
watchers: [],
348-
https: [port: 4000, keyfile: "priv/server.key", certfile: "priv/server.pem"]
349-
```
350-
351-
This tells phoenix to listen on port 4000 with the just generated certificate. Furthermore, the handler tells Phoenix to use Cowboy2.
352-
353-
If you now start the application with `mix phx.server` and go to https://localhost:4000 the browser will tell that the connection is not secure with for example NET::ERR_CERT_AUTHORITY_INVALID. This is because the certificate is self signed, and not by a certificate authority. You can open the certificate in for example Keychain on Mac OS X and tell your OS to trust the certificate.
354-
355-
*[Source](https://maartenvanvliet.nl/2017/12/15/upgrading_phoenix_to_http2/)*
356-
357303
## Using SSL
304+
358305
If you want to connect to Dgraph using SSL you have to set the `:ssl` config to `true` and provide a certificate:
359306
360307
```elixir
@@ -420,9 +367,7 @@ defmodule ExDgraph do
420367
- `:password` - User password;
421368
- `:pool_size` - maximum pool size;
422369
- `:max_overflow` - maximum number of workers created if pool is empty
423-
- `:timeout` - Connect timeout in milliseconds (default: `#{@timeout}`)
424-
Poolboy will block the current process and wait for an available worker,
425-
failing after a timeout, when the pool is full;
370+
- `:timeout` - Connect timeout in milliseconds (default: `#{@timeout}`) for DBConnection and the GRPC client deadline.
426371
- `:pool` - The connection pool. Defaults to `DbConnection.Poolboy`.
427372
- `:ssl` - If to use ssl for the connection (please see configuration example).
428373
If you set this option, you also have to set `cacertfile` to the correct path.

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule ExDgraph.MixProject do
44
def project do
55
[
66
app: :ex_dgraph,
7-
version: "0.2.0-beta.1",
7+
version: "0.2.0-beta.2",
88
elixir: "~> 1.6",
99
start_permanent: Mix.env() == :prod,
1010
deps: deps(),
@@ -46,7 +46,7 @@ defmodule ExDgraph.MixProject do
4646
{:grpc, "~> 0.3.1"},
4747
{:gun, "1.3.0"},
4848
{:protobuf, "~> 0.5"},
49-
{:poison, "~> 4.0.1"},
49+
{:poison, "~> 3.1"},
5050
{:poolboy, "~> 1.5.2"},
5151
{:db_connection, "~> 1.1"},
5252
{:retry, "~> 0.11.2"},

mix.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"credo": {:hex, :credo, "1.0.2", "88bc918f215168bf6ce7070610a6173c45c82f32baa08bdfc80bf58df2d103b6", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
99
"db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
1010
"earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm"},
11+
"elixir_uuid": {:hex, :elixir_uuid, "1.2.0", "ff26e938f95830b1db152cb6e594d711c10c02c6391236900ddd070a6b01271d", [:mix], [], "hexpm"},
1112
"ex_doc": {:hex, :ex_doc, "0.18.4", "4406b8891cecf1352f49975c6d554e62e4341ceb41b9338949077b0d4a97b949", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
1213
"excoveralls": {:hex, :excoveralls, "0.10.5", "7c912c4ec0715a6013647d835c87cde8154855b9b84e256bc7a63858d5f284e3", [:mix], [{:hackney, "~> 1.13", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
13-
"elixir_uuid": {:hex, :elixir_uuid, "1.2.0", "ff26e938f95830b1db152cb6e594d711c10c02c6391236900ddd070a6b01271d", [:mix], [], "hexpm"},
1414
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
1515
"file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm"},
1616
"fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], [], "hexpm"},
@@ -29,7 +29,7 @@
2929
"morphix": {:hex, :morphix, "0.6.0", "78902c71672a5de64759fb5847f9bed708eb82bc0eb017f1e5cd95f93f1a167b", [:mix], [], "hexpm"},
3030
"nimble_parsec": {:hex, :nimble_parsec, "0.4.0", "ee261bb53214943679422be70f1658fff573c5d0b0a1ecd0f18738944f818efe", [:mix], [], "hexpm"},
3131
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
32-
"poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm"},
32+
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
3333
"poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm"},
3434
"protobuf": {:hex, :protobuf, "0.5.4", "2e1b8eec211aff034ad8a14e3674220b0158bfb9a3c7128ac9d2a1ed1b3724d3", [:mix], [], "hexpm"},
3535
"ranch": {:hex, :ranch, "1.6.2", "6db93c78f411ee033dbb18ba8234c5574883acb9a75af0fb90a9b82ea46afa00", [:rebar3], [], "hexpm"},

0 commit comments

Comments
 (0)