diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c670ca7..f8892d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,43 +2,12 @@ name: CI on: push: - branches: [main, master] + branches: [main] pull_request: - branches: [main, master] + branches: [main] jobs: ci: - name: OTP ${{ matrix.otp }} - runs-on: ubuntu-latest - strategy: - matrix: - otp: ['27.2', '28.0'] - steps: - - uses: actions/checkout@v4 - - - uses: erlef/setup-beam@v1 - with: - otp-version: ${{ matrix.otp }} - rebar3-version: '3.24' - - - name: Restore rebar3 cache - uses: actions/cache@v4 - with: - path: | - _build - ~/.cache/rebar3 - key: ${{ runner.os }}-otp-${{ matrix.otp }}-rebar3-${{ hashFiles('rebar.lock') }} - restore-keys: | - ${{ runner.os }}-otp-${{ matrix.otp }}-rebar3- - - - name: Compile - run: rebar3 compile - - - name: Format check - run: rebar3 fmt --check - - - name: XRef - run: rebar3 xref - - - name: Dialyzer - run: rebar3 dialyzer + uses: Taure/erlang-ci/.github/workflows/ci.yml@v1 + with: + enable-eunit: false diff --git a/rebar.config b/rebar.config index c78a422..83e8ea4 100644 --- a/rebar.config +++ b/rebar.config @@ -7,6 +7,14 @@ {shell, [{apps, [egql_nova]}]}. +{xref_ignores, [ + {egql_nova, execute, 2}, + {egql_nova_controller, graphql, 1}, + {egql_nova_controller, graphiql, 1}, + {egql_nova_plug, pre_request, 2}, + {egql_nova_plug, post_request, 2} +]}. + {project_plugins, [ erlfmt, rebar3_ex_doc, diff --git a/src/egql_nova.erl b/src/egql_nova.erl index 71e3ecd..20f09f7 100644 --- a/src/egql_nova.erl +++ b/src/egql_nova.erl @@ -9,11 +9,12 @@ execute(Query, Params) -> -spec execute(binary(), map(), map()) -> map(). execute(Query, Params, Ctx) -> OpName = maps:get(<<"operationName">>, Params, undefined), - Vars = case maps:get(<<"variables">>, Params, #{}) of - null -> #{}; - V when is_map(V) -> V; - _ -> #{} - end, + Vars = + case maps:get(<<"variables">>, Params, #{}) of + null -> #{}; + V when is_map(V) -> V; + _ -> #{} + end, case graphql:parse(Query) of {ok, AST} -> try diff --git a/src/egql_nova_controller.erl b/src/egql_nova_controller.erl index 6c80426..fef3b7e 100644 --- a/src/egql_nova_controller.erl +++ b/src/egql_nova_controller.erl @@ -11,7 +11,7 @@ graphql(#{json := Body} = Req) -> Result = egql_nova:execute(Query, Body, Ctx), {json, 200, #{}, Result}; graphql(#{body := RawBody} = Req) -> - Body = jsone:decode(RawBody), + Body = json:decode(RawBody), Query = maps:get(<<"query">>, Body, <<>>), Ctx = build_context(Req), Result = egql_nova:execute(Query, Body, Ctx), @@ -22,32 +22,35 @@ graphiql(_Req) -> {ok, 200, #{<<"content-type">> => <<"text/html">>}, graphiql_html()}. build_context(Req) -> - ExtraCtx = case Req of - #{extra_state := #{context := C}} when is_map(C) -> C; - _ -> #{} - end, + ExtraCtx = + case Req of + #{extra_state := #{context := C}} when is_map(C) -> C; + _ -> #{} + end, ExtraCtx. graphiql_html() -> - <<" - - - GraphiQL - - - - - - - -
Loading...
- - -">>. + << + "\n" + "\n" + "\n" + " GraphiQL\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n" + "\n" + "
Loading...
\n" + " \n" + "\n" + "" + >>. diff --git a/src/egql_nova_plug.erl b/src/egql_nova_plug.erl index 36f6c63..5d445b2 100644 --- a/src/egql_nova_plug.erl +++ b/src/egql_nova_plug.erl @@ -11,13 +11,14 @@ pre_request(Req, #{context_fun := Fun} = _Options) when is_function(Fun, 1) -> Ctx = Fun(Req), - Req2 = case Req of - #{extra_state := ES} when is_map(ES) -> - ExistingCtx = maps:get(context, ES, #{}), - Req#{extra_state => ES#{context => maps:merge(ExistingCtx, Ctx)}}; - _ -> - Req#{extra_state => #{context => Ctx}} - end, + Req2 = + case Req of + #{extra_state := ES} when is_map(ES) -> + ExistingCtx = maps:get(context, ES, #{}), + Req#{extra_state => ES#{context => maps:merge(ExistingCtx, Ctx)}}; + _ -> + Req#{extra_state => #{context => Ctx}} + end, {ok, Req2}; pre_request(Req, _Options) -> {ok, Req}.