Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Prepare for development #12

Merged
merged 19 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from 18 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
64 changes: 64 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Elixir CI

on:
push:
branches: [ "main", "master" ]
pull_request:
branches: [ "main", "master" ]

env:
MIX_ENV: test

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
name: Install Erlang and Elixir
id: setup-beam
with:
version-file: .tool-versions
version-type: strict

- name: Deps Cache
uses: actions/cache@v4
with:
key: ${{ runner.os }}-deps-${{ hashFiles('./mix.lock') }}
restore-keys: |
${{ runner.os }}-deps
path: ./deps

- name: Build Cache
uses: actions/cache@v4
with:
key: ${{ runner.os }}-build-${{ hashFiles('./mix.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ hashFiles('./mix.lock') }}
path: ./_build

- name: Run docker compose
uses: hoverkraft-tech/[email protected]
with:
up-flags: "--wait"

- name: Install dependencies
run: mix deps.get

- name: Compiles without warnings
run: mix compile --warnings-as-errors

- name: Check Formatting
run: mix format --check-formatted

# TODO: Enable credo later
# - name: Run credo
# run: mix credo

- name: Run tests
run: mix test
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
elixir 1.17.3
erlang 27.2
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

8 changes: 0 additions & 8 deletions Dockerfile

This file was deleted.

14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center"><img src="logo.png"></img></p>

[![Build Status](https://travis-ci.com/Revmaker/gremlex.svg?branch=master)](https://travis-ci.com/Revmaker/gremlex)
[![CI](https://github.com/coingaming/gremlex/actions/workflows/ci.yaml/badge.svg)](https://github.com/coingaming/gremlex/actions/workflows/ci.yaml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

# Gremlex
Expand All @@ -23,7 +23,7 @@ end

## Examples

#### Basic Usage
### Basic Usage
The two main modules that you'll want to use are `Gremlex.Graph` and `Gremlex.Client`.

`Gremlex.Graph` is the module that hosts all the functions needed to build a Gremlin query.
Expand All @@ -46,7 +46,7 @@ iex(3)> Graph.g() |> Graph.v() |> Client.query
]}
```

#### Gremlin Query to Gremlex
### Gremlin Query to Gremlex
This gremlin query:
```
g.V().has("name","marko")
Expand Down Expand Up @@ -106,10 +106,6 @@ simply have the parameters that need to be dynamically read at run time set to `

## Contributing

$ git clone https://github.com/Revmaker/gremlex.git
$ git clone https://github.com/coingaming/gremlex.git
$ cd gremlex
$ mix deps.get
$ mix test

Once you've made your additions and `mix test` passes, go ahead and open a PR!
Note: Please make sure you run `mix format` on the touched files :)
$ ./scripts/test.sh
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
import Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
Expand Down
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :gremlex,
host: "127.0.0.1",
Expand Down
4 changes: 3 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :gremlex,
host: {:system, "GREMLEX_HOST", "127.0.0.1"},
Expand All @@ -7,3 +7,5 @@ config :gremlex,
pool_size: 10,
overflow: 10,
secure: false

config :logger, level: :warning
7 changes: 0 additions & 7 deletions coveralls.json

This file was deleted.

5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
graph:
image: tinkerpop/gremlin-server:3.7
ports:
- 8182:8182

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 8182:8182
- 8183:8182

different internal - external port

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is usually done for reserved/assigned ports. In the case of port 8182 it is not assigned. If it ever conflicts with someone's local setup we can set this as an env var like

ports:
  - ${GREMLEX_SERVER_PORT}:8182

and use an .env file like

GREMLEX_SERVER_PORT=8182

22 changes: 0 additions & 22 deletions docker-compose/Dockerfile-gremlin

This file was deleted.

21 changes: 0 additions & 21 deletions docker-compose/docker-compose.yml

This file was deleted.

57 changes: 0 additions & 57 deletions docker-compose/gremlin-conf.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions docker-compose/test-entrypoint.sh

This file was deleted.

20 changes: 12 additions & 8 deletions lib/gremlex/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule Gremlex.Client do
delay

_ ->
Logger.warn("Found invalid ping delay value: #{value} -- Defaulting to 0")
Logger.warning("Found invalid ping delay value: #{value} -- Defaulting to 0")
0
end
end
Expand Down Expand Up @@ -83,11 +83,15 @@ defmodule Gremlex.Client do
payload =
query
|> Request.new()
|> Poison.encode!()

:poolboy.transaction(:gremlex, fn worker_pid ->
GenServer.call(worker_pid, {:query, payload, timeout}, timeout)
end, timeout)
|> Jason.encode!()

:poolboy.transaction(
:gremlex,
fn worker_pid ->
GenServer.call(worker_pid, {:query, payload, timeout}, timeout)
end,
timeout
)
end

# Server Methods
Expand Down Expand Up @@ -123,7 +127,7 @@ defmodule Gremlex.Client do
defp recv(socket, acc \\ []) do
case Socket.Web.recv!(socket) do
{:text, data} ->
response = Poison.decode!(data)
response = Jason.decode!(data)
result = Deserializer.deserialize(response)
status = response["status"]["code"]
error_message = response["status"]["message"]
Expand Down Expand Up @@ -168,7 +172,7 @@ defmodule Gremlex.Client do
end

def measure(function) do
{time, result} = function |> :timer.tc
{time, result} = function |> :timer.tc()
{Kernel./(time, 1_000_000), result}
end
end
9 changes: 7 additions & 2 deletions lib/gremlex/deserializer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ defmodule Gremlex.Deserializer do
|> Enum.reduce(%{}, fn
[%{"@type" => "g:T", "@value" => key}, %{"@type" => type, "@value" => value}], acc ->
Map.put(acc, key, deserialize(type, value))

[key, %{"@type" => type, "@value" => value}], acc ->
Map.put(acc, key, deserialize(type, value))
[%{"@type" => "g:T", "@value" => key}, value], acc -> Map.put(acc, key, value)
[key, value], acc -> Map.put(acc, key, value)

[%{"@type" => "g:T", "@value" => key}, value], acc ->
Map.put(acc, key, value)

[key, value], acc ->
Map.put(acc, key, value)
end)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/gremlex/edge.ex
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
defmodule Gremlex.Edge do
alias Gremlex.Deserializer
@enforce_keys [:label, :id, :in_vertex, :out_vertex, :properties]
@derive [Poison.Encoder]
@type t :: %Gremlex.Edge{
label: String.t(),
id: number(),
properties: map(),
in_vertex: Gremlex.Vertex.t(),
out_vertex: Gremlex.Vertex.t()
}
@derive Jason.Encoder
defstruct [:label, :id, :in_vertex, :out_vertex, :properties]

def new(
Expand Down
2 changes: 1 addition & 1 deletion lib/gremlex/path.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Gremlex.Path do

@type t :: %Path{labels: List.t(), objects: List.t()}
@enforce_keys [:labels, :objects]
@derive [Poison.Encoder]
@derive Jason.Encoder
defstruct [:labels, :objects]

def from_response(%{"labels" => labels, "objects" => objects}) do
Expand Down
5 changes: 3 additions & 2 deletions lib/gremlex/request.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Gremlex.Request do
alias Gremlex.Graph
@derive [Poison.Encoder]
alias Gremlex.Request.Id
@derive Jason.Encoder
@op "eval"
@processor ""
@enforce_keys [:op, :processor, :requestId, :args]
Expand All @@ -12,7 +13,7 @@ defmodule Gremlex.Request do
@spec new(String.t()) :: Request
def new(query) when is_binary(query) do
args = %{gremlin: query, language: "gremlin-groovy"}
%Gremlex.Request{requestId: UUID.uuid4(), args: args, op: @op, processor: @processor}
%Gremlex.Request{requestId: Id.generate(), args: args, op: @op, processor: @processor}
end

@spec new(Gremlex.Graph.t()) :: Request
Expand Down
Loading