Skip to content

Fixup string bool handling #212

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

Open
wants to merge 33 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
279f117
Documentation typo
jlouis Jan 30, 2019
fc46374
Implement the necessary bits for storing delayed functions
jlouis Jan 30, 2019
5df9a35
Implement an apply chain assuming no further defer
jlouis Jan 30, 2019
1018830
Implement map/2 in the non-defer case
jlouis Jan 30, 2019
6b1ae4b
Allow staged defer
jlouis Jan 30, 2019
17b0199
Document graphql:map/2
jlouis Jan 31, 2019
31548e9
Fix wrong list handling in variable coercion
jlouis Mar 12, 2019
3fca5fd
Adapt input values to use a default of `undefined`
jlouis Apr 10, 2019
7f64c14
Clean up how parameters are checked
jlouis Apr 10, 2019
7049cba
If processing parameters, everything are #vardef{}s
jlouis Apr 10, 2019
a8c7a64
Hoist out default parameter checking
jlouis Apr 10, 2019
5c5e649
Reuse code paths properly
jlouis Apr 10, 2019
16b503e
Streamline pathing
jlouis Apr 10, 2019
151ee28
Rid ourselves of a comment full of misinformation
jlouis Apr 10, 2019
6cd3253
Do not have a separate check_param pass
jlouis Apr 10, 2019
b5bed5c
Coerce default parameters in a better way
jlouis Apr 11, 2019
27a85f3
Introduce a failing test case for default handling
jlouis Apr 11, 2019
3a21c97
Use the records default value
jlouis Apr 11, 2019
1c1b1c7
Correct the type we have, for field arguments
jlouis Apr 11, 2019
96a7d77
Introduce a record for variables
jlouis Apr 11, 2019
ec3b61c
Handle default values for variables.
jlouis Apr 11, 2019
751e7d8
Document fix
jlouis Apr 11, 2019
58ea68f
Fix wrong coerce for compat reasons
jlouis Apr 12, 2019
6a04c7c
Provide a test case for the coercer
jlouis Apr 12, 2019
898ced7
Fixup scalar handling of grayscale
jlouis Apr 14, 2019
bdd0d24
Supply a new query type
jlouis Apr 14, 2019
6dc6d17
Fold take_arg/3 into caller, fix Tau/Sigma subsumption
jlouis Apr 14, 2019
fddd9f1
Use defaults for arguments as well, if vars are passed
jlouis Apr 14, 2019
a475a4a
Default parameters should be coerced, not checked
jlouis Apr 14, 2019
47cf978
Undefined is ok in coercions
jlouis Apr 14, 2019
bf69eaa
Correct wrong canonicalization defaults
jlouis Apr 14, 2019
fc76a2d
Merge pull request #207 from shopgun/fix/default-args-coercion
jlouis Apr 14, 2019
bb9588e
Fixup string bool handling
zntuszntusTW Jun 18, 2020
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
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,30 @@ the compatibility issues you are likely to encounter.

## [Unreleased]

### Compatibility

* The error code `param_mismatch` was removed in lieu of
`type_mismatch` due to a rewrite in the type checker of error
handling.
* The error code `non_null` will now report `type_mismatch` instead.
* The error code `enum_not_found` will now be reported as
`unknown_enum`
* If a string literal is given in place of an enum, the error code
will now be `enum_string_literal` rather than `enum_not_found`.

### Added

* Add proper support for OTP release 21 (by getong, 18年梦醒). Detect the
OTP 21 version, and if present, use the new stack-trace form. This
ensures backwards compatibility as well as proper stack trace
handling in new OTP releases.
* New command `graphql:map/2`. Given a `Result` of the form `{ok, Val} |
{defer, Token}` the call to `graphql:map(F, Result)` will apply `F`
to the result. Either now, or in the case of a defer, when the defer
completes. This yields an alternative way to handle events which
cannot be completed right away. Long running work is usually better
handled in a spawned process, but simpler changes can be handled
within the context of the GraphQL process.
* New command `graphql:sync/3`. Calling `graphql:sync(Ctx, Pid, Msg)`
will place a message into the GraphQL mailbox. When this message
occurs, we will send `Pid` a message `Msg`. This is useful for e.g.,
Expand All @@ -28,6 +46,11 @@ the compatibility issues you are likely to encounter.

### Fixed

* Default variable value expansion has been fixed. If you have a
situation where a field-arg has a default value, you have supplied a
parameter for that value, say `foo(x: $k)` and you then omit `$k` in
your query, the underlying default (in this case the default for
`x`) is now picked up properly.
* Re-instate the operation type in the callers context
* Remove the occurrence of fragment names in `path` components of
errors. These are not allowed per the Jun2018 specification and
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ specification, except for a few areas:
In addition, we are working towards June 2018 compliance. We already
implemented many of the changes in the system. But we are still
missing some parts. The implementation plan is on a demand driven
basis for Shopgun currently, in that we tend to implement things are
basis for Shopgun currently, in that we tend to implement things when
there is a need for them.

# Documentation
Expand Down
23 changes: 21 additions & 2 deletions src/graphql.erl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
-module(graphql).


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

-compile({no_auto_import, [monitor/2]}).

%% GraphQL Documents
-export([
parse/1,
Expand All @@ -26,7 +27,9 @@
%% Deferred execution
-export([
token/1, reply_cast/2,
sync/3
sync/3,
monitor/2,
map/2
]).

%% Schema Definitions
Expand All @@ -47,6 +50,10 @@
-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{}.
Expand Down Expand Up @@ -74,6 +81,18 @@ token(#{ defer_process := Proc, defer_request_id := ReqId }) ->
sync(#{ defer_process := Proc, defer_request_id := ReqId }, Pid, Msg) ->
Proc ! {'$graphql_sync', ReqId, Pid, Msg}.

-spec monitor(pid(), result()) -> result().
monitor(_Worker, {ok, Value}) -> {ok, Value};
monitor(_Worker, {error, Reason}) -> {error, Reason};
monitor(Worker, {defer, Token}) -> monitor(Worker, {defer, Token, #{}});
monitor(Worker, {defer, Token, Map}) when is_pid(Worker) -> {defer, Token, Map#{ worker => Worker}}.

map(F, {ok, Value}) -> F({ok, Value});
map(F, {error, Reason}) -> F({error, Reason});
map(F, {defer, Token}) -> map(F, {defer, Token, #{}});
map(F, {defer, Token, #{ apply := App} = M}) -> {defer, Token, M#{ apply := queue:in(F, App)}};
map(F, {defer, Token, #{} = M}) -> {defer, Token, M#{ apply => queue:in(F, queue:new())}}.

%% @private
token_ref({'$graphql_token', _, _, Ref}) -> Ref.

Expand Down
Loading