From 1f7aae333dda384183063edd33f527406104fefb Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 11:58:09 +0200 Subject: [PATCH 01/19] Prepare for development --- .github/workflows/ci.yaml | 67 +++++++++++++++++++++++++++++++ .tool-versions | 2 + .travis.yml | 17 -------- config/config.exs | 2 +- config/dev.exs | 2 +- config/test.exs | 2 +- coveralls.json | 7 ---- docker-compose.yml | 5 +++ docker-compose/Dockerfile-gremlin | 22 ---------- docker-compose/docker-compose.yml | 21 ---------- docker-compose/gremlin-conf.yaml | 57 -------------------------- docker-compose/test-entrypoint.sh | 7 ---- lib/gremlex/client.ex | 14 ++++--- mix.exs | 3 +- mix.lock | 41 +++++++------------ scripts/test.sh | 7 ++++ test/graph_test.exs | 4 +- 17 files changed, 111 insertions(+), 169 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 .tool-versions delete mode 100644 .travis.yml delete mode 100644 coveralls.json create mode 100644 docker-compose.yml delete mode 100644 docker-compose/Dockerfile-gremlin delete mode 100644 docker-compose/docker-compose.yml delete mode 100644 docker-compose/gremlin-conf.yaml delete mode 100755 docker-compose/test-entrypoint.sh create mode 100755 scripts/test.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..3022635 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,67 @@ +name: Elixir CI + +on: + push: + branches: [ "main", "master" ] + pull_request: + branches: [ "main", "master" ] + +env: + MIX_ENV: test + +permissions: + contents: read + +jobs: + test: + # Set up a Gremlin Server instance + services: + rabbitmq: + image: "tinkerpop/gremlin-server:3.7" + ports: + - "8182:8182" + + runs-on: ubuntu-latest + name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} + steps: + - uses: erlef/setup-beam@v1 + name: Install Erlang and Elixir + id: setup-beam + with: + version-file: .tool-versions + version-type: strict + + - name: Checkout code + uses: actions/checkout@v4 + + - 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: 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 diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..eb4268d --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +elixir 1.17.3 +erlang 27.2 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 747a9f3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -sudo: required -language: elixir -elixir: '1.6' -services: -- docker -before_install: -- mix format --check-formatted --dry-run -install: -- docker-compose -f docker-compose/docker-compose.yml build -script: -- docker-compose -f docker-compose/docker-compose.yml run gremlex -after_script: -- docker-compose -f docker-compose/docker-compose.yml down --remove-orphans -- commitlint --from master -notifications: - slack: - secure: cntKmnZkcVHNbsWdvWpkiy8EC8itHezo5DUOJoWfsfht3dBaPM0v/XtuZ9ELwlJGfDxSOdCodrgK7CXasrQHWlWQNpNRU3EyxhZnx8AtC0sNvKB8uSrUuvs0XVAXxNL2vYrlSKti6Xl3/2J9POIMmxAjYGYr5+4xcQDXvpMt1RzpQtp/R6X9F9QB9aAF5plTFeWlN8fMSsfUnyeozN9ZRFOjUUoWJSbjQpgrMBi2H3mucOb/YUIAiWbjltbDQ8HSfXhmy883aBaAhzYSLe+Omh/plKVawi77KrZ4WxWnLigQy/P9auH5K5h5BolbDtyNE7A4vBzUrniUpscX9a55XOIWJxt/UV3FRb0Grb9SAlfQlTz1CFmowD6KLJWfrafS0enEMj2rKVG6Pe8h9ZXgxCeTKv5hoteQIsahkqVBuoYszogR8rywNss8TNvgSsixLePCDQ/+KYPFVaMaWl9ePJIuOiGLUuwWhpBowgt1naHcdNdTpqnokXe+N8c1FZDvmPk6rInXhQ3Dlr+VQNDurld9hVLyZPguGSX458U6v2Z7Mr35SdQIrC77XJQOOmpyGo7X0VXr7Yp6tBOkoWzQ0tG5Bj/744V4Ki8NV6rAJkuU9ujHwiqRap9udFgMpwGU1dVCe3n4NlxHX/uI+4/Opg4PYZmYX+99wxYB8hD7suA= diff --git a/config/config.exs b/config/config.exs index 29e9df4..61e6861 100644 --- a/config/config.exs +++ b/config/config.exs @@ -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 diff --git a/config/dev.exs b/config/dev.exs index defcd03..6e8ca10 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config config :gremlex, host: "127.0.0.1", diff --git a/config/test.exs b/config/test.exs index 7ee11e1..780f781 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config config :gremlex, host: {:system, "GREMLEX_HOST", "127.0.0.1"}, diff --git a/coveralls.json b/coveralls.json deleted file mode 100644 index 5209e60..0000000 --- a/coveralls.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "skip_files": [ - "lib/gremlex.ex", - "test/support/mock_server.ex", - "test/support/mocks.ex" - ] -} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..46f671e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,5 @@ +services: + graph: + image: tinkerpop/gremlin-server:3.7 + ports: + - 8182:8182 diff --git a/docker-compose/Dockerfile-gremlin b/docker-compose/Dockerfile-gremlin deleted file mode 100644 index 8906e0c..0000000 --- a/docker-compose/Dockerfile-gremlin +++ /dev/null @@ -1,22 +0,0 @@ -FROM ubuntu:bionic - -WORKDIR /srv - -ARG GREMLIN_VER=3.3.2 - -RUN apt-get update - -RUN apt-get install -y unzip wget openjdk-11-jdk - -RUN wget https://archive.apache.org/dist/tinkerpop/$GREMLIN_VER/apache-tinkerpop-gremlin-server-$GREMLIN_VER-bin.zip - -RUN unzip apache-tinkerpop-gremlin-server-$GREMLIN_VER-bin.zip - -WORKDIR /srv/apache-tinkerpop-gremlin-server-$GREMLIN_VER - -COPY gremlin-conf.yaml conf/gremlin-conf.yaml - -EXPOSE 8182 - -ENTRYPOINT ["bin/gremlin-server.sh", "conf/gremlin-conf.yaml"] - diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml deleted file mode 100644 index 3f0de39..0000000 --- a/docker-compose/docker-compose.yml +++ /dev/null @@ -1,21 +0,0 @@ -version: "3" -services: - gremlin: - build: - context: "." - dockerfile: Dockerfile-gremlin - expose: - - "8182" - gremlex: - links: - - gremlin - build: - context: ../ - dockerfile: Dockerfile - entrypoint: ./docker-compose/test-entrypoint.sh - environment: - - GREMLEX_HOST=gremlin - depends_on: - - gremlin - volumes: - - ../:/app diff --git a/docker-compose/gremlin-conf.yaml b/docker-compose/gremlin-conf.yaml deleted file mode 100644 index a5c3ba8..0000000 --- a/docker-compose/gremlin-conf.yaml +++ /dev/null @@ -1,57 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -# Note that TinkerPop does not include gremlin-python dependencies in -# its distributions. This file cannot be used as a configuration file -# to Gremlin Server unless those dependencies are installed on the -# Gremlin Server path with: -# -# bin/gremlin-server.sh -i org.apache.tinkerpop gremlin-python x.y.z -# -# The primary change in this file to enable the GremlinJythonScriptEngine -# is the addition of "gremlin-jython" to the "scriptEngines" field. - -host: 0.0.0.0 -port: 8182 -threadPoolWorker: 1 -gremlinPool: 8 -scriptEvaluationTimeout: 30000 -graphs: { - graph: conf/tinkergraph-empty.properties} -scriptEngines: { - gremlin-groovy: { - plugins: { org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {}, - org.apache.tinkerpop.gremlin.tinkergraph.jsr223.TinkerGraphGremlinPlugin: {}, - org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [java.lang.Math], methodImports: [java.lang.Math#*]}, - org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {files: [scripts/generate-modern.groovy]}}}, - gremlin-jython: {}, - gremlin-python: {} -} -serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3d0] }} # application/vnd.gremlin-v3.0+gryo - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v3.0+gryo-stringd - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3d0] }} # application/json -metrics: { - slf4jReporter: {enabled: true, interval: 180000}} -strictTransactionManagement: false -threadPoolBoss: 1 -maxInitialLineLength: 4096 -maxHeaderSize: 8192 -maxChunkSize: 8192 -maxContentLength: 65536 -maxAccumulationBufferComponents: 1024 -resultIterationBatchSize: 64 diff --git a/docker-compose/test-entrypoint.sh b/docker-compose/test-entrypoint.sh deleted file mode 100755 index 7f1399c..0000000 --- a/docker-compose/test-entrypoint.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -export MIX_ENV=test - -mix deps.get && \ - mix compile --warnings-as-errors && \ - mix test --trace --cover diff --git a/lib/gremlex/client.ex b/lib/gremlex/client.ex index a8b4952..8d9f7bf 100644 --- a/lib/gremlex/client.ex +++ b/lib/gremlex/client.ex @@ -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 @@ -85,9 +85,13 @@ defmodule Gremlex.Client do |> Request.new() |> Poison.encode!() - :poolboy.transaction(:gremlex, fn worker_pid -> - GenServer.call(worker_pid, {:query, payload, timeout}, timeout) - end, timeout) + :poolboy.transaction( + :gremlex, + fn worker_pid -> + GenServer.call(worker_pid, {:query, payload, timeout}, timeout) + end, + timeout + ) end # Server Methods @@ -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 diff --git a/mix.exs b/mix.exs index 30501c7..e1263b8 100644 --- a/mix.exs +++ b/mix.exs @@ -7,6 +7,7 @@ defmodule Gremlex.MixProject do version: "0.3.2", elixir: "~> 1.6", elixirc_paths: elixirc_paths(Mix.env()), + elixirc_options: [warnings_as_errors: true], start_permanent: Mix.env() == :prod, deps: deps(), description: description(), @@ -44,7 +45,6 @@ defmodule Gremlex.MixProject do defp deps do [ {:poison, "~> 3.1"}, - {:httpoison, "~> 1.3.1"}, {:confex, "~> 3.2.3"}, {:uuid, "~> 1.1"}, {:poolboy, "~> 1.5.1"}, @@ -52,7 +52,6 @@ defmodule Gremlex.MixProject do {:mix_test_watch, "~> 0.3", only: :dev, runtime: false}, {:ex_doc, "~> 0.19", only: :dev, runtime: false}, {:mock, "~> 0.2.0", only: :test}, - {:excoveralls, "~> 0.7", only: :test}, {:stream_data, "~> 0.1", only: :test} ] end diff --git a/mix.lock b/mix.lock index d8754c8..4858a1f 100644 --- a/mix.lock +++ b/mix.lock @@ -1,28 +1,17 @@ %{ - "certifi": {:hex, :certifi, "2.4.2", "75424ff0f3baaccfd34b1214184b6ef616d89e420b258bb0a5ea7d7bc628f7f0", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"}, - "confex": {:hex, :confex, "3.2.3", "f3e29188448c790dd75b416daeedddddcce0a9bb657721cd9ed3d857a2de0434", [:mix], [], "hexpm"}, - "earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm"}, - "ex_doc": {:hex, :ex_doc, "0.19.3", "3c7b0f02851f5fc13b040e8e925051452e41248f685e40250d7e40b07b9f8c10", [:mix], [{:earmark, "~> 1.2", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, - "excoveralls": {:hex, :excoveralls, "0.10.4", "b86230f0978bbc630c139af5066af7cd74fd16536f71bc047d1037091f9f63a9", [:mix], [{:hackney, "~> 1.13", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"}, - "file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm"}, - "hackney": {:hex, :hackney, "1.15.0", "287a5d2304d516f63e56c469511c42b016423bcb167e61b611f6bad47e3ca60e", [:rebar3], [{:certifi, "2.4.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, - "httpoison": {:hex, :httpoison, "1.3.1", "7ac607311f5f706b44e8b3fab736d0737f2f62a31910ccd9afe7227b43edb7f0", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, - "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, - "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, - "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, - "meck": {:hex, :meck, "0.8.13", "ffedb39f99b0b99703b8601c6f17c7f76313ee12de6b646e671e3188401f7866", [:rebar3], [], "hexpm"}, - "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"}, - "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"}, - "mix_test_watch": {:hex, :mix_test_watch, "0.9.0", "c72132a6071261893518fa08e121e911c9358713f62794a90c95db59042af375", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm"}, - "mock": {:hex, :mock, "0.2.1", "bfdba786903e77f9c18772dee472d020ceb8ef000783e737725a4c8f54ad28ec", [:mix], [{:meck, "~> 0.8.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"}, - "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"}, - "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"}, - "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, - "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm"}, - "socket": {:hex, :socket, "0.3.13", "98a2ab20ce17f95fb512c5cadddba32b57273e0d2dba2d2e5f976c5969d0c632", [:mix], [], "hexpm"}, - "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"}, - "stream_data": {:hex, :stream_data, "0.4.2", "fa86b78c88ec4eaa482c0891350fcc23f19a79059a687760ddcf8680aac2799b", [:mix], [], "hexpm"}, - "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"}, - "uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm"}, + "confex": {:hex, :confex, "3.2.3", "f3e29188448c790dd75b416daeedddddcce0a9bb657721cd9ed3d857a2de0434", [:mix], [], "hexpm", "ee04f41e9780be59713dfdb0d5132486db361bc79255318a8d6afdf165736107"}, + "earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm", "000aaeff08919e95e7aea13e4af7b2b9734577b3e6a7c50ee31ee88cab6ec4fb"}, + "ex_doc": {:hex, :ex_doc, "0.19.3", "3c7b0f02851f5fc13b040e8e925051452e41248f685e40250d7e40b07b9f8c10", [:mix], [{:earmark, "~> 1.2", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "0e11d67e662142fc3945b0ee410c73c8c956717fbeae4ad954b418747c734973"}, + "file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm", "0d50da6b04c58e101a3793b1600f9a03b86e3a8057b192ac1766013d35706fa6"}, + "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5fbc8e549aa9afeea2847c0769e3970537ed302f93a23ac612602e805d9d1e7f"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "adf0218695e22caeda2820eaba703fa46c91820d53813a2223413da3ef4ba515"}, + "meck": {:hex, :meck, "0.8.13", "ffedb39f99b0b99703b8601c6f17c7f76313ee12de6b646e671e3188401f7866", [:rebar3], [], "hexpm", "d34f013c156db51ad57cc556891b9720e6a1c1df5fe2e15af999c84d6cebeb1a"}, + "mix_test_watch": {:hex, :mix_test_watch, "0.9.0", "c72132a6071261893518fa08e121e911c9358713f62794a90c95db59042af375", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "817dec4a7f6edf260258002f99ac8ffaf7a8f395b27bf2d13ec24018beecec8a"}, + "mock": {:hex, :mock, "0.2.1", "bfdba786903e77f9c18772dee472d020ceb8ef000783e737725a4c8f54ad28ec", [:mix], [{:meck, "~> 0.8.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "d440b817e4e3505fe2d17963b7e783ae72875011dc6ac757c21904a8cc3578ac"}, + "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm", "5c040b8469c1ff1b10093d3186e2e10dbe483cd73d79ec017993fb3985b8a9b3"}, + "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm", "fec8660eb7733ee4117b85f55799fd3833eb769a6df71ccf8903e8dc5447cfce"}, + "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm", "dad79704ce5440f3d5a3681c8590b9dc25d1a561e8f5a9c995281012860901e3"}, + "socket": {:hex, :socket, "0.3.13", "98a2ab20ce17f95fb512c5cadddba32b57273e0d2dba2d2e5f976c5969d0c632", [:mix], [], "hexpm", "f82ea9833ef49dde272e6568ab8aac657a636acb4cf44a7de8a935acb8957c2e"}, + "stream_data": {:hex, :stream_data, "0.4.2", "fa86b78c88ec4eaa482c0891350fcc23f19a79059a687760ddcf8680aac2799b", [:mix], [], "hexpm", "54d6bf6f1e5e27fbf4a7784a2bffbb993446d0efd079debca0f27bf859c0d1cf"}, + "uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm", "c790593b4c3b601f5dc2378baae7efaf5b3d73c4c6456ba85759905be792f2ac"}, } diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..b0e1001 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,7 @@ +set -e +MIX_ENV=test + +docker-compose up -d + +mix deps.get +mix test \ No newline at end of file diff --git a/test/graph_test.exs b/test/graph_test.exs index 3d61c07..c1bafa4 100644 --- a/test/graph_test.exs +++ b/test/graph_test.exs @@ -261,7 +261,7 @@ defmodule Gremlex.GraphTests do end test "creates a vertex when the id is a number" do - check all n <- integer() do + check all(n <- integer()) do actual_graph = v(n) expected_graph = %Vertex{id: n, label: ""} assert actual_graph == expected_graph @@ -1082,7 +1082,7 @@ defmodule Gremlex.GraphTests do describe "choose/3" do test "adds a choose function to the queue" do - actual_graph = g() |> choose(g |> has_label("TEST"), [g |> v("1")]) + actual_graph = g() |> choose(g() |> has_label("TEST"), [g() |> v("1")]) has_label_part = Queue.in({"hasLabel", ["TEST"]}, Queue.new()) vertex_part = Queue.in({"V", ["1"]}, Queue.new()) expected_graph = Queue.in({"choose", [has_label_part, vertex_part]}, Queue.new()) From 4c48fa0c39f0ff14c563f72f9cf78b04c5a4da2d Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 12:01:46 +0200 Subject: [PATCH 02/19] remove workflow name --- .github/workflows/ci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3022635..9f6139b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,7 +22,6 @@ jobs: - "8182:8182" runs-on: ubuntu-latest - name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} steps: - uses: erlef/setup-beam@v1 name: Install Erlang and Elixir From 82ca5924a2ad609d3ddf1fe2929e05129d0824bd Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 13:16:20 +0200 Subject: [PATCH 03/19] fix order --- .github/workflows/ci.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9f6139b..ede1515 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -23,6 +23,9 @@ jobs: 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 @@ -30,9 +33,6 @@ jobs: version-file: .tool-versions version-type: strict - - name: Checkout code - uses: actions/checkout@v4 - - name: Deps Cache uses: actions/cache@v4 with: From 04d24d44d0e24ef3e7f90e4696280c97499a8329 Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 13:18:03 +0200 Subject: [PATCH 04/19] format files --- lib/gremlex/deserializer.ex | 9 +++++++-- test/deserializer_test.exs | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/gremlex/deserializer.ex b/lib/gremlex/deserializer.ex index 050d37d..007db81 100644 --- a/lib/gremlex/deserializer.ex +++ b/lib/gremlex/deserializer.ex @@ -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 diff --git a/test/deserializer_test.exs b/test/deserializer_test.exs index b05f7e0..9f44f71 100644 --- a/test/deserializer_test.exs +++ b/test/deserializer_test.exs @@ -7,7 +7,7 @@ defmodule Grmelex.DeserializerTests do describe "deserialize/2" do test "should deserialize integers" do - check all n <- integer() do + check all(n <- integer()) do assert deserialize("g:Int64", n) == n assert deserialize("g:Int32", n) == n assert deserialize("g:Float", n) == n @@ -15,7 +15,7 @@ defmodule Grmelex.DeserializerTests do end test "should deserialize floats and doubles" do - check all f <- float() do + check all(f <- float()) do assert deserialize("g:Float", f) == f assert deserialize("g:Double", f) == f end From c153c2ce2554f47ab22a4ee5742bc240db1290bf Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 13:23:04 +0200 Subject: [PATCH 05/19] bump stream_data --- config/test.exs | 2 ++ mix.exs | 2 +- mix.lock | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/config/test.exs b/config/test.exs index 780f781..b02b145 100644 --- a/config/test.exs +++ b/config/test.exs @@ -7,3 +7,5 @@ config :gremlex, pool_size: 10, overflow: 10, secure: false + +config :logger, level: :warning diff --git a/mix.exs b/mix.exs index e1263b8..411b529 100644 --- a/mix.exs +++ b/mix.exs @@ -52,7 +52,7 @@ defmodule Gremlex.MixProject do {:mix_test_watch, "~> 0.3", only: :dev, runtime: false}, {:ex_doc, "~> 0.19", only: :dev, runtime: false}, {:mock, "~> 0.2.0", only: :test}, - {:stream_data, "~> 0.1", only: :test} + {:stream_data, "~> 1.0", only: :test} ] end diff --git a/mix.lock b/mix.lock index 4858a1f..6c773e4 100644 --- a/mix.lock +++ b/mix.lock @@ -12,6 +12,6 @@ "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm", "fec8660eb7733ee4117b85f55799fd3833eb769a6df71ccf8903e8dc5447cfce"}, "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm", "dad79704ce5440f3d5a3681c8590b9dc25d1a561e8f5a9c995281012860901e3"}, "socket": {:hex, :socket, "0.3.13", "98a2ab20ce17f95fb512c5cadddba32b57273e0d2dba2d2e5f976c5969d0c632", [:mix], [], "hexpm", "f82ea9833ef49dde272e6568ab8aac657a636acb4cf44a7de8a935acb8957c2e"}, - "stream_data": {:hex, :stream_data, "0.4.2", "fa86b78c88ec4eaa482c0891350fcc23f19a79059a687760ddcf8680aac2799b", [:mix], [], "hexpm", "54d6bf6f1e5e27fbf4a7784a2bffbb993446d0efd079debca0f27bf859c0d1cf"}, + "stream_data": {:hex, :stream_data, "1.1.3", "15fdb14c64e84437901258bb56fc7d80aaf6ceaf85b9324f359e219241353bfb", [:mix], [], "hexpm", "859eb2be72d74be26c1c4f272905667672a52e44f743839c57c7ee73a1a66420"}, "uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm", "c790593b4c3b601f5dc2378baae7efaf5b3d73c4c6456ba85759905be792f2ac"}, } From 1ddb9f11d633dc444e48842d55c0409cfe17b074 Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 13:28:41 +0200 Subject: [PATCH 06/19] remove Dockerfile --- Dockerfile | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 780acfa..0000000 --- a/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM elixir:latest - -RUN mix local.hex --force -RUN mix local.rebar --force - -WORKDIR /app - -COPY . . From cbc9f4f8b936f130da60fb3933448c430e2b6444 Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 13:35:42 +0200 Subject: [PATCH 07/19] try with compose --- .github/workflows/ci.yaml | 12 +++++------- test/client_test.exs | 16 ++++++++-------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ede1515..a512564 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,13 +14,6 @@ permissions: jobs: test: - # Set up a Gremlin Server instance - services: - rabbitmq: - image: "tinkerpop/gremlin-server:3.7" - ports: - - "8182:8182" - runs-on: ubuntu-latest steps: - name: Checkout code @@ -49,6 +42,11 @@ jobs: ${{ runner.os }}-build-${{ hashFiles('./mix.lock') }} path: ./_build + - name: Run docker compose + uses: hoverkraft-tech/compose-action@v2.0.1 + with: + docker-flags: "--wait" + - name: Install dependencies run: mix deps.get diff --git a/test/client_test.exs b/test/client_test.exs index ce42d2b..f739616 100644 --- a/test/client_test.exs +++ b/test/client_test.exs @@ -4,20 +4,20 @@ defmodule Gremlex.ClientTests do describe "query/1" do test "that it can return a successful query" do - {result, response} = g() |> v() |> query + {result, response} = g() |> v() |> query() assert result == :ok assert Enum.count(response) > 0 end test "returns an error :script_evaluation_error for a bad request" do - {result, response, error_message} = g() |> to(1) |> query + {result, response, error_message} = g() |> to(1) |> query() assert result == :error assert response == :script_evaluation_error assert error_message != "" end test "allows you to create a new vertex" do - {result, response} = g() |> add_v("person") |> property("name", "jasper") |> query + {result, response} = g() |> add_v("person") |> property("name", "jasper") |> query() assert Enum.count(response) == 1 assert result == :ok [vertex] = response @@ -33,7 +33,7 @@ defmodule Gremlex.ClientTests do |> add_v("person") |> property("name", "jasper") |> property("address", address) - |> query + |> query() assert Enum.count(response) == 1 assert result == :ok @@ -48,7 +48,7 @@ defmodule Gremlex.ClientTests do end test "allows you to create a new vertex without a property" do - {result, response} = g() |> add_v("person") |> query + {result, response} = g() |> add_v("person") |> query() assert Enum.count(response) == 1 assert result == :ok [vertex] = response @@ -65,14 +65,14 @@ defmodule Gremlex.ClientTests do test "allows you to create a relationship between two vertices" do {_, [s]} = g() |> add_v("foo") |> property("name", "bar") |> query() {_, [t]} = g() |> add_v("bar") |> property("name", "baz") |> query() - {result, response} = g() |> v(s.id) |> add_e("isfriend") |> to(t) |> query + {result, response} = g() |> v(s.id) |> add_e("isfriend") |> to(t) |> query() assert result == :ok [edge] = response assert edge.label == "isfriend" end test "allows you to get all edges" do - {result, response} = g() |> e() |> query + {result, response} = g() |> e() |> query() assert result == :ok case response do @@ -93,7 +93,7 @@ defmodule Gremlex.ClientTests do test "returns empty list when there is no content retrieved" do {_, response} = - g() |> v() |> has_label("person") |> has("doesntExist", "doesntExist") |> query + g() |> v() |> has_label("person") |> has("doesntExist", "doesntExist") |> query() assert(response == []) end From 5a87c9c4244112a1628f99366051bea81abdc36c Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 13:37:08 +0200 Subject: [PATCH 08/19] fix option --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a512564..8fba696 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -45,7 +45,7 @@ jobs: - name: Run docker compose uses: hoverkraft-tech/compose-action@v2.0.1 with: - docker-flags: "--wait" + compose-flags: "--wait" - name: Install dependencies run: mix deps.get From 89ad26f14c0d0764a671d4daf8e0285d99eb8c17 Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 13:39:58 +0200 Subject: [PATCH 09/19] remove flag --- .github/workflows/ci.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8fba696..874ccde 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -44,8 +44,6 @@ jobs: - name: Run docker compose uses: hoverkraft-tech/compose-action@v2.0.1 - with: - compose-flags: "--wait" - name: Install dependencies run: mix deps.get From e5f698c19dd19647fae5844d3b944642a599e366 Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 13:41:59 +0200 Subject: [PATCH 10/19] fix flag name --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 874ccde..7f2a85e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -44,6 +44,8 @@ jobs: - name: Run docker compose uses: hoverkraft-tech/compose-action@v2.0.1 + with: + up-flags: "--wait" - name: Install dependencies run: mix deps.get From b82d3622508d6cd565a405b3ed91d22aebd6d391 Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 13:51:02 +0200 Subject: [PATCH 11/19] remove uuid and mock --- lib/gremlex/request.ex | 3 ++- lib/gremlex/request/id.ex | 45 +++++++++++++++++++++++++++++++++++++++ mix.exs | 3 --- test/request_test.exs | 21 ++++++------------ 4 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 lib/gremlex/request/id.ex diff --git a/lib/gremlex/request.ex b/lib/gremlex/request.ex index 776f4f9..b08edbc 100644 --- a/lib/gremlex/request.ex +++ b/lib/gremlex/request.ex @@ -1,5 +1,6 @@ defmodule Gremlex.Request do alias Gremlex.Graph + alias Gremlex.Request.Id @derive [Poison.Encoder] @op "eval" @processor "" @@ -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 diff --git a/lib/gremlex/request/id.ex b/lib/gremlex/request/id.ex new file mode 100644 index 0000000..8f05d6e --- /dev/null +++ b/lib/gremlex/request/id.ex @@ -0,0 +1,45 @@ +defmodule Gremlex.Request.Id do + @moduledoc """ + UUID generation vendored from `Ecto.UUID` + """ + + @doc """ + Generates a unique request id + """ + @spec generate() :: String.t() + def generate, do: encode(bingenerate()) + + defp bingenerate do + <> = :crypto.strong_rand_bytes(16) + <> + end + + defp encode( + <> + ) do + <> + end + + @compile {:inline, e: 1} + + defp e(0), do: ?0 + defp e(1), do: ?1 + defp e(2), do: ?2 + defp e(3), do: ?3 + defp e(4), do: ?4 + defp e(5), do: ?5 + defp e(6), do: ?6 + defp e(7), do: ?7 + defp e(8), do: ?8 + defp e(9), do: ?9 + defp e(10), do: ?a + defp e(11), do: ?b + defp e(12), do: ?c + defp e(13), do: ?d + defp e(14), do: ?e + defp e(15), do: ?f +end diff --git a/mix.exs b/mix.exs index 411b529..fe97ab1 100644 --- a/mix.exs +++ b/mix.exs @@ -46,12 +46,9 @@ defmodule Gremlex.MixProject do [ {:poison, "~> 3.1"}, {:confex, "~> 3.2.3"}, - {:uuid, "~> 1.1"}, {:poolboy, "~> 1.5.1"}, {:socket, "~> 0.3"}, - {:mix_test_watch, "~> 0.3", only: :dev, runtime: false}, {:ex_doc, "~> 0.19", only: :dev, runtime: false}, - {:mock, "~> 0.2.0", only: :test}, {:stream_data, "~> 1.0", only: :test} ] end diff --git a/test/request_test.exs b/test/request_test.exs index b1464c3..aff7cac 100644 --- a/test/request_test.exs +++ b/test/request_test.exs @@ -1,27 +1,20 @@ defmodule Gremlex.RequestTests do use ExUnit.Case alias Gremlex.Request - import Mock import Gremlex.Graph describe "new/1" do test "construct the proper payload for a gremlin graph query" do - with_mock UUID, uuid4: fn -> "uuid" end do - query = g() |> v() - payload = "g.V()" - args = %{gremlin: payload, language: "gremlin-groovy"} - expected_request = %Request{requestId: "uuid", args: args, op: "eval", processor: ""} - assert Request.new(query) == expected_request - end + query = g() |> v() + payload = "g.V()" + args = %{gremlin: payload, language: "gremlin-groovy"} + assert %Request{args: ^args, op: "eval", processor: ""} = Request.new(query) end test "construct the proper payload for a gremlin plain query" do - with_mock UUID, uuid4: fn -> "uuid" end do - payload = "g.V()" - args = %{gremlin: payload, language: "gremlin-groovy"} - expected_request = %Request{requestId: "uuid", args: args, op: "eval", processor: ""} - assert Request.new(payload) == expected_request - end + payload = "g.V()" + args = %{gremlin: payload, language: "gremlin-groovy"} + assert %Request{args: ^args, op: "eval", processor: ""} = Request.new(payload) end end end From 3644cb9e5b2454710ba398e0e6be751c41b6e5bf Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 14:32:41 +0200 Subject: [PATCH 12/19] replace Poison with Jason --- lib/gremlex/client.ex | 4 ++-- lib/gremlex/edge.ex | 2 +- lib/gremlex/path.ex | 2 +- lib/gremlex/request.ex | 2 +- lib/gremlex/vertex.ex | 2 +- lib/gremlex/vertex_property.ex | 2 +- mix.exs | 2 +- mix.lock | 7 +------ 8 files changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/gremlex/client.ex b/lib/gremlex/client.ex index 8d9f7bf..6ac8bcd 100644 --- a/lib/gremlex/client.ex +++ b/lib/gremlex/client.ex @@ -83,7 +83,7 @@ defmodule Gremlex.Client do payload = query |> Request.new() - |> Poison.encode!() + |> Jason.encode!() :poolboy.transaction( :gremlex, @@ -127,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"] diff --git a/lib/gremlex/edge.ex b/lib/gremlex/edge.ex index e4a6716..3b93cf1 100644 --- a/lib/gremlex/edge.ex +++ b/lib/gremlex/edge.ex @@ -1,7 +1,6 @@ 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(), @@ -9,6 +8,7 @@ defmodule Gremlex.Edge do in_vertex: Gremlex.Vertex.t(), out_vertex: Gremlex.Vertex.t() } + @derive Jason.Encoder defstruct [:label, :id, :in_vertex, :out_vertex, :properties] def new( diff --git a/lib/gremlex/path.ex b/lib/gremlex/path.ex index a11b791..d8f0be8 100644 --- a/lib/gremlex/path.ex +++ b/lib/gremlex/path.ex @@ -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 diff --git a/lib/gremlex/request.ex b/lib/gremlex/request.ex index b08edbc..0da9693 100644 --- a/lib/gremlex/request.ex +++ b/lib/gremlex/request.ex @@ -1,7 +1,7 @@ defmodule Gremlex.Request do alias Gremlex.Graph alias Gremlex.Request.Id - @derive [Poison.Encoder] + @derive Jason.Encoder @op "eval" @processor "" @enforce_keys [:op, :processor, :requestId, :args] diff --git a/lib/gremlex/vertex.ex b/lib/gremlex/vertex.ex index 897af22..52f94e1 100644 --- a/lib/gremlex/vertex.ex +++ b/lib/gremlex/vertex.ex @@ -4,7 +4,7 @@ defmodule Gremlex.Vertex do @type t :: %Gremlex.Vertex{label: String.t(), id: number(), properties: map()} @enforce_keys [:label, :id] - @derive [Poison.Encoder] + @derive Jason.Encoder defstruct [:label, :id, :properties] def add_properties(%Vertex{properties: nil} = vertex, properties) do diff --git a/lib/gremlex/vertex_property.ex b/lib/gremlex/vertex_property.ex index 975f9f9..1a8d408 100644 --- a/lib/gremlex/vertex_property.ex +++ b/lib/gremlex/vertex_property.ex @@ -6,7 +6,7 @@ defmodule Gremlex.VertexProperty do vertex: number() } @enforce_keys [:label, :id, :value] - @derive [Poison.Encoder] + @derive Jason.Encoder defstruct [:label, :id, :value, :vertex] def from_response(%{"id" => json_id, "value" => value, "vertex" => vertex, "label" => label}) do diff --git a/mix.exs b/mix.exs index fe97ab1..3241adb 100644 --- a/mix.exs +++ b/mix.exs @@ -44,7 +44,7 @@ defmodule Gremlex.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:poison, "~> 3.1"}, + {:jason, "~> 1.4"}, {:confex, "~> 3.2.3"}, {:poolboy, "~> 1.5.1"}, {:socket, "~> 0.3"}, diff --git a/mix.lock b/mix.lock index 6c773e4..a2fe8ae 100644 --- a/mix.lock +++ b/mix.lock @@ -2,16 +2,11 @@ "confex": {:hex, :confex, "3.2.3", "f3e29188448c790dd75b416daeedddddcce0a9bb657721cd9ed3d857a2de0434", [:mix], [], "hexpm", "ee04f41e9780be59713dfdb0d5132486db361bc79255318a8d6afdf165736107"}, "earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm", "000aaeff08919e95e7aea13e4af7b2b9734577b3e6a7c50ee31ee88cab6ec4fb"}, "ex_doc": {:hex, :ex_doc, "0.19.3", "3c7b0f02851f5fc13b040e8e925051452e41248f685e40250d7e40b07b9f8c10", [:mix], [{:earmark, "~> 1.2", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "0e11d67e662142fc3945b0ee410c73c8c956717fbeae4ad954b418747c734973"}, - "file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm", "0d50da6b04c58e101a3793b1600f9a03b86e3a8057b192ac1766013d35706fa6"}, + "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5fbc8e549aa9afeea2847c0769e3970537ed302f93a23ac612602e805d9d1e7f"}, "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "adf0218695e22caeda2820eaba703fa46c91820d53813a2223413da3ef4ba515"}, - "meck": {:hex, :meck, "0.8.13", "ffedb39f99b0b99703b8601c6f17c7f76313ee12de6b646e671e3188401f7866", [:rebar3], [], "hexpm", "d34f013c156db51ad57cc556891b9720e6a1c1df5fe2e15af999c84d6cebeb1a"}, - "mix_test_watch": {:hex, :mix_test_watch, "0.9.0", "c72132a6071261893518fa08e121e911c9358713f62794a90c95db59042af375", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "817dec4a7f6edf260258002f99ac8ffaf7a8f395b27bf2d13ec24018beecec8a"}, - "mock": {:hex, :mock, "0.2.1", "bfdba786903e77f9c18772dee472d020ceb8ef000783e737725a4c8f54ad28ec", [:mix], [{:meck, "~> 0.8.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "d440b817e4e3505fe2d17963b7e783ae72875011dc6ac757c21904a8cc3578ac"}, "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm", "5c040b8469c1ff1b10093d3186e2e10dbe483cd73d79ec017993fb3985b8a9b3"}, - "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm", "fec8660eb7733ee4117b85f55799fd3833eb769a6df71ccf8903e8dc5447cfce"}, "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm", "dad79704ce5440f3d5a3681c8590b9dc25d1a561e8f5a9c995281012860901e3"}, "socket": {:hex, :socket, "0.3.13", "98a2ab20ce17f95fb512c5cadddba32b57273e0d2dba2d2e5f976c5969d0c632", [:mix], [], "hexpm", "f82ea9833ef49dde272e6568ab8aac657a636acb4cf44a7de8a935acb8957c2e"}, "stream_data": {:hex, :stream_data, "1.1.3", "15fdb14c64e84437901258bb56fc7d80aaf6ceaf85b9324f359e219241353bfb", [:mix], [], "hexpm", "859eb2be72d74be26c1c4f272905667672a52e44f743839c57c7ee73a1a66420"}, - "uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm", "c790593b4c3b601f5dc2378baae7efaf5b3d73c4c6456ba85759905be792f2ac"}, } From 418e48cbafc6f3bd6b620901f1900e4e83c8f0e0 Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 14:40:24 +0200 Subject: [PATCH 13/19] bump ex_doc and confex --- mix.exs | 8 ++++---- mix.lock | 13 +++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/mix.exs b/mix.exs index 3241adb..d27741f 100644 --- a/mix.exs +++ b/mix.exs @@ -13,7 +13,7 @@ defmodule Gremlex.MixProject do description: description(), package: package(), test_coverage: [tool: ExCoveralls], - source_url: "https://github.com/Revmaker/gremlex", + source_url: "https://github.com/coingaming/gremlex", preferred_cli_env: [ coveralls: :test, "coveralls.detail": :test, @@ -45,10 +45,10 @@ defmodule Gremlex.MixProject do defp deps do [ {:jason, "~> 1.4"}, - {:confex, "~> 3.2.3"}, + {:confex, "~> 3.0"}, {:poolboy, "~> 1.5.1"}, {:socket, "~> 0.3"}, - {:ex_doc, "~> 0.19", only: :dev, runtime: false}, + {:ex_doc, "~> 0.34", only: :dev, runtime: false}, {:stream_data, "~> 1.0", only: :test} ] end @@ -61,7 +61,7 @@ defmodule Gremlex.MixProject do [ name: "gremlex", licenses: ["MIT"], - links: %{"GitHub" => "https://github.com/Revmaker/gremlex"} + links: %{"GitHub" => "https://github.com/coingaming/gremlex"} ] end end diff --git a/mix.lock b/mix.lock index a2fe8ae..20d6077 100644 --- a/mix.lock +++ b/mix.lock @@ -1,11 +1,12 @@ %{ - "confex": {:hex, :confex, "3.2.3", "f3e29188448c790dd75b416daeedddddcce0a9bb657721cd9ed3d857a2de0434", [:mix], [], "hexpm", "ee04f41e9780be59713dfdb0d5132486db361bc79255318a8d6afdf165736107"}, - "earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm", "000aaeff08919e95e7aea13e4af7b2b9734577b3e6a7c50ee31ee88cab6ec4fb"}, - "ex_doc": {:hex, :ex_doc, "0.19.3", "3c7b0f02851f5fc13b040e8e925051452e41248f685e40250d7e40b07b9f8c10", [:mix], [{:earmark, "~> 1.2", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "0e11d67e662142fc3945b0ee410c73c8c956717fbeae4ad954b418747c734973"}, + "confex": {:hex, :confex, "3.5.1", "c29ea741715de06afe6294ea2e127ee7a54382f2b33656b9ed7eedf3e7b6fcaf", [:mix], [], "hexpm", "c72824a267edc96c09a35f6556f48c139d00393dd1b726b18faeb8efee62c0b0"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.43", "34b2f401fe473080e39ff2b90feb8ddfeef7639f8ee0bbf71bb41911831d77c5", [:mix], [], "hexpm", "970a3cd19503f5e8e527a190662be2cee5d98eed1ff72ed9b3d1a3d466692de8"}, + "ex_doc": {:hex, :ex_doc, "0.37.1", "65ca30d242082b95aa852b3b73c9d9914279fff56db5dc7b3859be5504417980", [:mix], [{:earmark_parser, "~> 1.4.42", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "6774f75477733ea88ce861476db031f9399c110640752ca2b400dbbb50491224"}, "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, - "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5fbc8e549aa9afeea2847c0769e3970537ed302f93a23ac612602e805d9d1e7f"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "adf0218695e22caeda2820eaba703fa46c91820d53813a2223413da3ef4ba515"}, - "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm", "5c040b8469c1ff1b10093d3186e2e10dbe483cd73d79ec017993fb3985b8a9b3"}, + "makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"}, + "makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"}, + "makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"}, "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm", "dad79704ce5440f3d5a3681c8590b9dc25d1a561e8f5a9c995281012860901e3"}, "socket": {:hex, :socket, "0.3.13", "98a2ab20ce17f95fb512c5cadddba32b57273e0d2dba2d2e5f976c5969d0c632", [:mix], [], "hexpm", "f82ea9833ef49dde272e6568ab8aac657a636acb4cf44a7de8a935acb8957c2e"}, "stream_data": {:hex, :stream_data, "1.1.3", "15fdb14c64e84437901258bb56fc7d80aaf6ceaf85b9324f359e219241353bfb", [:mix], [], "hexpm", "859eb2be72d74be26c1c4f272905667672a52e44f743839c57c7ee73a1a66420"}, From 9118ddc57ad0fda4da002e6e5e1ebdd6deddc140 Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 15:12:58 +0200 Subject: [PATCH 14/19] improve test --- test/client_test.exs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/client_test.exs b/test/client_test.exs index f739616..613ee5e 100644 --- a/test/client_test.exs +++ b/test/client_test.exs @@ -72,8 +72,7 @@ defmodule Gremlex.ClientTests do end test "allows you to get all edges" do - {result, response} = g() |> e() |> query() - assert result == :ok + {:ok, response} = g() |> e() |> query() case response do [] -> @@ -82,7 +81,7 @@ defmodule Gremlex.ClientTests do |> v(0) |> add_e("edge_2_electric_booglaoo") |> to(%Gremlex.Vertex{id: 1, properties: nil, label: "no"}) - |> query + |> query() assert Enum.count(edges) > 0 From 0f684b75c342c204ad14cfe0d78b03489c1240b7 Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 15:19:43 +0200 Subject: [PATCH 15/19] fix README.md --- README.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a938267..8dbd1f1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@

-[![Build Status](https://travis-ci.com/Revmaker/gremlex.svg?branch=master)](https://travis-ci.com/Revmaker/gremlex) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) # Gremlex @@ -23,7 +22,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. @@ -46,7 +45,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") @@ -106,10 +105,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 From 2f4f98d390a295c608887e75bc7ba5cd56d18edc Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 15:22:15 +0200 Subject: [PATCH 16/19] add CI badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8dbd1f1..2285346 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@

+[![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 From 47dc2dd61fbed644790e0de4328a16bcf927532b Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Mon, 17 Feb 2025 15:23:19 +0200 Subject: [PATCH 17/19] remove coveralls reference --- mix.exs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/mix.exs b/mix.exs index d27741f..ec8f14c 100644 --- a/mix.exs +++ b/mix.exs @@ -12,14 +12,7 @@ defmodule Gremlex.MixProject do deps: deps(), description: description(), package: package(), - test_coverage: [tool: ExCoveralls], source_url: "https://github.com/coingaming/gremlex", - preferred_cli_env: [ - coveralls: :test, - "coveralls.detail": :test, - "coveralls.post": :test, - "coveralls.html": :test - ], docs: [ # The main page in the docs main: "Gremlex", From c887a78b9e5dad354ce10a1b1a8e2fe3c2f728ca Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Tue, 18 Feb 2025 09:43:04 +0200 Subject: [PATCH 18/19] fix flaky tests --- test/client_test.exs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/test/client_test.exs b/test/client_test.exs index 613ee5e..934b2d1 100644 --- a/test/client_test.exs +++ b/test/client_test.exs @@ -2,11 +2,21 @@ defmodule Gremlex.ClientTests do use Gremlex use ExUnit.Case + setup do + # Cleanup DB + {:ok, _} = query("g.V().drop()") + :ok + end + describe "query/1" do test "that it can return a successful query" do - {result, response} = g() |> v() |> query() - assert result == :ok - assert Enum.count(response) > 0 + person_id = System.unique_integer([:positive]) + vertex_id = "person#{person_id}" + + assert {:ok, [%{label: ^vertex_id}]} = + g() |> add_v(vertex_id) |> property("name", "John Doe") |> query() + + assert {:ok, [%{label: ^vertex_id}]} = g() |> v() |> query() end test "returns an error :script_evaluation_error for a bad request" do @@ -72,22 +82,12 @@ defmodule Gremlex.ClientTests do end test "allows you to get all edges" do - {:ok, response} = g() |> e() |> query() - - case response do - [] -> - {_res, edges} = - g() - |> v(0) - |> add_e("edge_2_electric_booglaoo") - |> to(%Gremlex.Vertex{id: 1, properties: nil, label: "no"}) - |> query() - - assert Enum.count(edges) > 0 - - edges -> - assert Enum.count(edges) > 0 - end + v1_id = System.unique_integer([:positive]) + v2_id = System.unique_integer([:positive]) + {_, [s]} = g() |> add_v("vertex_#{v1_id}") |> property("name", "vertex#{v1_id}") |> query() + {_, [t]} = g() |> add_v("vertex_#{v2_id}") |> property("name", "vertex#{v2_id}") |> query() + + {:ok, [%{label: "isfriend"}]} = g() |> v(s.id) |> add_e("isfriend") |> to(t) |> query() end test "returns empty list when there is no content retrieved" do From 3a0f405aa503fe61f783e9ab9bb59e42a8cf6e48 Mon Sep 17 00:00:00 2001 From: ignaciogoldchluk-yolo Date: Tue, 18 Feb 2025 16:14:27 +0200 Subject: [PATCH 19/19] bump minimum Elixir version --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index ec8f14c..abe76ba 100644 --- a/mix.exs +++ b/mix.exs @@ -5,7 +5,7 @@ defmodule Gremlex.MixProject do [ app: :gremlex, version: "0.3.2", - elixir: "~> 1.6", + elixir: "~> 1.14", elixirc_paths: elixirc_paths(Mix.env()), elixirc_options: [warnings_as_errors: true], start_permanent: Mix.env() == :prod,