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

Add GitHub CI #227

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
ci:
name: Run checks and tests over ${{matrix.otp}} and ${{matrix.os}}
runs-on: ${{matrix.os}}
container:
image: erlang:${{ matrix.otp }}

strategy:
fail-fast: false
matrix:
otp:
- "26.1"
- "25.3"
- "24.3"
os: ["ubuntu-22.04"]
include:
- otp: "23.3"
os: "ubuntu-20.04"

steps:
- uses: actions/checkout@v3

- name: Compile
run: make compile

- name: xref
run: make xref

- name: Common test
run: make test-cover

- name: Generate docs
run: make doc

- name: Dialyze
run: make dialyzer
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ test:
@$(REBAR) ct --verbosity 60 --spec test/test.spec

test-cover:
@$(REBAR) do ct -c, cover -v
@$(REBAR) do ct -c --spec test/test.spec, cover -v

xref:
@$(REBAR) xref

update:
@$(REBAR) update

doc:
@$(REBAR) edoc

.PHONY: compile clean dialyzer test update
12 changes: 12 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,15 @@
{geas_rebar3, {git, "https://github.com/crownedgrouse/geas_rebar3.git", {branch, "master"}}},
rebar3_hex
]}.

{xref_checks, [
undefined_function_calls,
undefined_functions,
deprecated_functions_calls,
deprecated_functions
]}.

{dialyzer, [
{warnings, [unknown]},
{plt_apps, all_deps}
]}.
35 changes: 23 additions & 12 deletions src/graphql.erl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-module(graphql).

-include_lib("graphql/include/graphql.hrl").
-include("graphql_internal.hrl").
%%-include("graphql_internal.hrl").
-include("graphql_schema.hrl").

-compile({no_auto_import, [monitor/2]}).
Expand Down Expand Up @@ -42,25 +42,35 @@
%% Internal
-export([token_ref/1]).

-type json() :: number() | binary() | true | false | null | #{ binary() | atom() => json() } | [json()] .
-type param_context() :: json().

-type json() :: number() | binary() | true | false | null | #{ binary() | atom() => json() } | [json()] .
-type schema_definition() :: {atom(), #{ atom() => term() }}.

-export_type([json/0, param_context/0]).

-type token() :: {'$graphql_token', pid(), reference(), reference()}.
-type defer_map() :: #{ worker => pid(),
timeout => non_neg_integer(),
apply => [fun()]}.
-type result() :: {ok, term()} | {error, term()} | {defer, token()} | {defer, token(), defer_map()}.
-type name() :: {name, pos_integer(), binary()} | binary().
-type document() :: #document{}.
-type directive() :: #directive{}.
-export_type([directive/0,
-type context() :: #{ params => vars(),
operation_name => binary() | undefined,
error_module => module(),
default_timeout => timeout(),
atom() => any() }.

-type vars() :: #{binary() => json()}.
-type result() :: {ok, term()} | {error, term()} | {defer, token()} | {defer, token(), defer_map()}.
-type resolver() :: fun ((context(), term(), binary(), vars()) -> result()).

-export_type([directive/0,
document/0,
context/0,
vars/0,
name/0,
token/0,
schema_field/0]).
schema_field/0,
resolver/0,
json/0]).

-define(DEFAULT_TIMEOUT, 3000).

Expand Down Expand Up @@ -141,15 +151,16 @@ load_schema(Mapping, Input) when is_list(Input) ->
{error, Err}
end.

-spec validate(document()) -> ok | {error, term()}.
-spec validate(document()) -> ok.
validate(AST) ->
graphql_validate:x(AST).

-spec type_check(document()) -> {ok, #{ atom() => term() }}.
-spec type_check(document()) -> {ok, #{ast := document(),
fun_env := graphql_check:fun_env()}}.
type_check(AST) ->
graphql_check:check(AST).

-spec type_check_params(any(), any(), any()) -> param_context().
-spec type_check_params(graphql_check:fun_env(), binary(), vars()) -> vars().
type_check_params(FunEnv, OpName, Vars) ->
graphql_check:check_params(FunEnv, OpName, Vars).

Expand Down
17 changes: 15 additions & 2 deletions src/graphql_check.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
-export([check/1, check_params/3]).
-export([funenv/1]).

-export_type([fun_env/0]).

-record(ctx,
{
path = [] :: [any()],
Expand All @@ -76,6 +78,8 @@
-type ty() :: schema_type() | schema_object().
-type ty_name() :: binary().

-opaque fun_env() :: #{binary() => #{binary() => #vardef{}}}.

%% This is a bidirectional type checker. It proceeds by running three
%% kinds of functions: synth(Gamma, E) -> {ok, T} | {error, Reason}
%% which synthesizes a given type out of its constituent parts.
Expand All @@ -89,7 +93,7 @@

%% Elaborate a type and also determine its polarity. This is used for
%% input and output types
-spec infer_type(ctx(), ty_name() | ty()) -> {ok, {polarity(), ty()}}.
-spec infer_type(ctx(), ty_name() | ty()) -> {ok, {polarity(), resolved_schema_type()}}.
infer_type(Ctx, Tau) ->
case infer_type(Tau) of
{error, Reason} ->
Expand All @@ -98,7 +102,7 @@ infer_type(Ctx, Tau) ->
{ok, {Polarity, TauPrime}}
end.

-spec infer_type(ty_name() | ty()) -> {polarity(), ty()} | {error, Reason :: term()}.
-spec infer_type(ty_name() | ty()) -> {polarity(), resolved_schema_type()} | {error, Reason :: term()}.
infer_type({non_null, Ty}) ->
case infer_type(Ty) of
{error, Reason} -> {error, Reason};
Expand Down Expand Up @@ -163,6 +167,8 @@ infer_output_type(Ctx, Ty) ->
%% Given a context and some graphql expression, we derive
%% a valid type for that expression. This is mostly handled by
%% a lookup into the environment.
-spec infer(ctx(), #directive{} | op() | frag() | frag_spread() | {var, any()}) ->
{ok, resolved_schema_type() | frag() | #vardef{}}.
infer(Ctx, #directive { id = ID }) ->
Name = graphql_ast:name(ID),
case graphql_schema:lookup(Name) of
Expand Down Expand Up @@ -543,6 +549,8 @@ check(Ctx, #op { vardefs = VDefs, directives = Dirs, selection_set = SSet } = Op

%% To check a document, establish a default context and
%% check the document.
-spec check(graphql:document()) -> {ok, #{ast := graphql:document(),
fun_env := fun_env()}}.
check(#document{} = Doc) ->
try check_(Doc) of Res -> Res
catch throw:{error, Path, Msg} ->
Expand Down Expand Up @@ -580,6 +588,7 @@ check_(#document{ definitions = Defs } = Doc) ->
%% This is the entry-point when checking parameters for an already parsed,
%% type checked and internalized query. It serves to verify that a requested
%% operation and its parameters matches the types in the operation referenced
-spec check_params(fun_env(), binary(), graphql:vars()) -> graphql:vars().
check_params(FunEnv, OpName, Params) ->
try
case operation(FunEnv, OpName, Params) of
Expand Down Expand Up @@ -696,6 +705,8 @@ sub_input_(_Tau, _Sigma) ->
%%
%% Fragments doesn't care if they sit inside lists or if the scope
%% type is non-null:
-spec sub_output(ctx(), object_type() | union_type() | interface_type(),
resolved_schema_type()) -> ok.
sub_output(Ctx, Tau, {list, Sigma}) ->
sub_output(Ctx, Tau, Sigma);
sub_output(Ctx, Tau, {non_null, Sigma}) ->
Expand Down Expand Up @@ -867,11 +878,13 @@ fields(_Ctx, #interface_type { fields = Fields }) -> {ok, Fields};
fields(_Ctx, #union_type {}) -> {ok, #{}}.

%% Build a varenv
-spec varenv([#vardef{}]) -> #{binary() => #vardef{}}.
varenv(VarList) ->
maps:from_list(
[{graphql_ast:name(Var), Def} || #vardef { id = Var } = Def <- VarList]).

%% Build a funenv
-spec funenv([frag() | op()]) -> fun_env().
funenv(Ops) ->
F = fun
(#frag{}, FE) -> FE;
Expand Down
1 change: 1 addition & 0 deletions src/graphql_err.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

-export([crash/2, err/2]).

-spec abort([any()], any()) -> no_return().
abort(Path, Msg) ->
abort(Path, uncategorized, Msg).

Expand Down
12 changes: 6 additions & 6 deletions src/graphql_execute.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
defer_target = top_level :: top_level | reference(),

%% The callers context given to the execute call
ctx = #{} :: #{ atom() => term() }
ctx = #{} :: graphql:context()
}).
-type ectx() :: #ectx{}.

Expand Down Expand Up @@ -74,10 +74,10 @@
work = #{} :: #{ source() => defer_closure() },
timeout :: non_neg_integer() }).

-spec x(graphql:ast()) -> #{ atom() => graphql:json() }.
-spec x(graphql:document()) -> #{ atom() => graphql:json() }.
x(X) -> x(#{ params => #{} }, X).

-spec x(term(), graphql:ast()) -> #{ atom() => graphql:json() }.
-spec x(term(), graphql:document()) -> #{ atom() => graphql:json() }.
x(Ctx, X) ->
Canon = canon_context(Ctx),
execute_request(Canon, X).
Expand Down Expand Up @@ -309,7 +309,7 @@ collect_fields(Ctx, Type, [#field{ directives = Dirs } = S |SS], Visited, Groupe
case view_include_skip_directives(Ctx, Dirs) of
include ->
collect_fields(Ctx, Type, SS, Visited,
orddict:append(alias(S), S, Grouped));
orddict:append(get_alias(S), S, Grouped));
skip ->
collect_fields(Ctx, Type, SS, Visited, Grouped)
end;
Expand Down Expand Up @@ -1034,8 +1034,8 @@ name({name, _, N}) -> N;
name('...') -> <<"...">>;
name(#field { id = ID }) -> name(ID).

alias(#field { alias = undefined, id = ID }) -> name(ID);
alias(#field { alias = Alias }) -> name(Alias).
get_alias(#field { alias = undefined, id = ID }) -> name(ID);
get_alias(#field { alias = Alias }) -> name(Alias).

field_type(#field { schema = SF }) -> SF.

Expand Down
3 changes: 1 addition & 2 deletions src/graphql_internal.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

-record(frag,
{ id :: '...' | graphql:name(), %% One variant is for inline fragments
ty :: undefined | graphql_base_type(),
ty :: any(), % undefined | graphql_base_type(), <- most of the time except graphql_check
directives = [] :: [graphql:directive()],
selection_set = [] :: [#field{}],
schema = undefined :: 'undefined' | any()
Expand Down Expand Up @@ -73,7 +73,6 @@
schema = undefined :: 'undefined' | any()
}).
-type op() :: #op{}.
-type context() :: #{ atom() => any() }.

%%% --- Parsed Schemas
%% Parsed schemas all starts with a p_ suffix
Expand Down
Loading