Commit graph

147 commits

Author SHA1 Message Date
Davide Briani
18d4e1b010
test: add tests on paginated relationships (#177)
Add tests to verify that relationships can be queried on the results of
GraphQL queries and mutations.

Querying paginated relationships on the result of deletions doesn't
correctly work yet.
Indeed, Ash currently queries relationships using a lateral join but
after the resource deletion has happened, so it looks like nothing is
related.

Signed-off-by: Davide Briani <davide@briani.dev>
2024-06-11 09:49:05 -04:00
Barnabas Jovanovics
8089164d74
feat: argument_input_types (#176)
* feat: argument_input_types

* use mix task to update formatter.exs

* update CheatSheet
2024-06-10 13:32:37 -04:00
Zach Daniel
4ff56a3c59
Add test for mutation with read action in simple data layer resource issue (#170)
Co-authored-by: Junil Chon <jichon@gmail.com>
2024-06-02 08:08:46 -04:00
Riccardo Binetti
62940c31ec
feat: relationship pagination (#166) 2024-05-26 09:50:54 -04:00
Zach Daniel
a6ca7fea67 feat: support queries/mutations on the domain 2024-05-24 15:51:19 -04:00
Riccardo Binetti
31d29e178f
improvement: deduplicate map types across domains (#164)
Allow having common NewType maps that are used in multiple domains and are
correctly deduplicated
2024-05-23 12:11:28 -04:00
Riccardo Binetti
2bc7b78aa6
fix: don't deduplicate argument types by argument name (#162)
As mentioned in the upgrade guide, the point of dropping auto generation of
types was avoiding conflicts when two arguments had the same name but different
types. Now that we require explicit generation, we can actually support that
usecase for, e.g., arguments with the same name but different types in
create/update mutations.
2024-05-23 08:58:25 -04:00
Barnabas Jovanovics
73e6974ea7
add test that shows problem with new auth field clean up (#153) 2024-05-13 08:18:15 -04:00
Alan Heywood
7386a5b627
improvement: make mutation result errors list non-nullable (#144)
* chore: regenerate cheat sheets

* improvement: make mutation result errors list non-nullable
2024-05-03 21:57:02 -04:00
Riccardo Binetti
833c1d5143
feat: allow passing custom descriptions to queries and mutations (#138)
Close #137
2024-04-29 15:01:26 -04:00
Zach Daniel
019632c420 fix: properly set actor on bulk action calls 2024-04-27 09:27:00 -04:00
Zach Daniel
fb74c2a4f3 improvement: use bulk actions for create/destroy 2024-04-25 23:28:37 -04:00
5b00697fef
chore: Add failing test case for string union values parsed as numbers. (#134) 2024-04-23 19:29:00 -04:00
Zach Daniel
ddae98cf40 chore: don't set domain for embedded resources 2024-04-11 23:49:22 -04:00
Zach Daniel
180d05545c improvement!: auto? managed_relationships by default
imporovement!: remove deprecated configuration
2024-04-01 16:02:30 -04:00
Zach Daniel
349086fbb8 improvement!: No longer automagically derive types 2024-04-01 15:27:43 -04:00
Riccardo Binetti
513c1ac68f
improvement!: port AshGraphql to Ash 3.0 (#123)
Step 1: update Ash

Step 2: mass rename Api to Domain

Step 3: Ash.Query.expr -> Ash.Expr.expr

Also change ref interpolation

Step 4: remove all warnings

Step 5: remove registries from tests

Step 6: fix filter

Step 7: private? -> !public?

Step 8: Ash.Calculation -> Ash.Resource.Calculation

Step 9: use depend_on_resources/1 -> resources/1

Step 10: add Domain to all resources

Step 11: use Ash module for all actions

Step 12: add public? true all around

Step 13: remove verbose? from options passed during Domain calls

Step 14: add simple_sat

Step 15: Ash.ErrorKind is no more, so remove code from errors

Step 16: sprinkle default_accept :* around tests

Step 17: replace Ash.Changeset.new/2 with Ash.Changeset.for_*

Step 18: calculation fixups

- Context is now a struct and arguments go under the arguments key
- Function based calculations receive a list of records
- Add a select to query-based loads
- select -> load

Step 19: pass the correct name to pass the policy in tests

Step 20: Ash.Query.new/2 is no more

Step 21: add AshGraphql.Resource.embedded? utility function

Use that instead of Ash.Type.embedded_type?(resource_or_type) since resources
are not types anymore

Step 22: handle struct + instance_of: Resource in unions

Resources are not type anymore so they need to be passed this way in unions

Step 23: ensure we only check GraphQL actions for pagination

All reads are now paginated by default, so this triggered a compilation error

Step 24: swap arguments for sort on calculations

Step 25: remove unused debug? option
2024-04-01 14:03:06 -04:00
Riccardo Binetti
9674614b62
feat: allow resources without types (#121)
* fix: regenerate spark formatter and cheatsheet

Make CI pass again

* feat: allow resources without types

Ensure they only expose generic action queries. Add checks to ensure that either
`type :resource_type` or `generate_object? false` is passed if it's needed.

Close #119
2024-03-28 11:16:32 -04:00
Riccardo Binetti
98baf6f0be
feat: allow providing descriptions for enum values (#117)
* chore: update ash to use Ash.Type.Enum descriptions

Contextually, remove an unreachable clause that caused dyalizer to fail,
see https://github.com/ash-project/ash/pull/873 for the commit that made
it unreachable

* feat: allow providing descriptions for enum values

If the module exports `graphql_describe_enum_value/1`, use that. Otherwise,
fallback to the Ash.Type.Enum value descriptions introduced in
https://github.com/ash-project/ash/pull/940.

Close #116
2024-03-25 23:43:59 -04:00
Zach Daniel
90dc20822d improvement: add hide_inputs to queries and mutations 2024-03-11 10:46:42 -04:00
Zach Daniel
21aed2dde5 chore: format 2024-02-12 10:06:14 -05:00
Junil Chon
9dd9f4c316 chore: add custom page of unions calculation test 2024-02-11 14:43:49 -05:00
Zach Daniel
328618fa94 fix: handle unions containing maps and vice versa 2024-02-11 14:10:20 -05:00
Riccardo Binetti
70eae5f421
fix: make results nullable again if root level errors are enabled (#114)
Building upon #110, this restores the old behaviour of the result being nullable
when root level errors are present.

While the result is guaranteed to not be nullable in standard conditions (since
either result or errors are always present), when errors are moved to the root
level it could become null, so declaring it non-nullable propagates the null up
to the data field.

This actually causes compatibility problems with some client libraries (e.g.
Relay) that expect the inner result to be null, _not_ data, if there's an error.

This also adds dedicated RootLevelErrors versions of the Api and the Schema
since the configuration is accessed at compile time now, so put_env was not
enough to test them correctly.
2024-02-09 09:36:23 -05:00
Riccardo Binetti
66d2f44443
feat: add Relay ID translation in mutation and queries (#109)
Adds a new option for queries and mutations that defines which arguments or
attributes will use a global Relay ID and their type. This allows automatically
decoding them before hitting their action.

This paves the way to automatic translation derived from the arguments, which
will be implemented subsequently.

---------

Co-authored-by: Zach Daniel <zachary.s.daniel@gmail.com>
2024-02-06 09:46:09 -05:00
Riccardo Binetti
6b09e7309e
improvement: make the items of fields and errors non-null (#112)
Last point left from the discussion on #105
2024-01-31 17:52:33 -05:00
Riccardo Binetti
8fff0d361d
improvement: make mutation arguments non-null (#111)
* improvement: make mutation arguments non-null

As discussed in #105 and #110, put this behind an opt-in configuration to avoid
breaking existing code.
The ID in update mutations is always non-null if non-null mutation arguments are
allowed, while input is non-null if it's allowed _and_ there is at least a
non-null field in the input.

Document the newly added config variable in the getting started guide.

* chore: enable non-null mutation arguments in tests
2024-01-31 17:52:01 -05:00
Riccardo Binetti
af4193feca
improvement: make mutation results non-nullable (#110)
Adjust rool level error tests: since result is now non-nullable, if the content
of the result is nil, the whole result becomes nil. Note that this is not a
breaking change since GraphQL always allows a field nullability to propagate
upwards in case of a field error (see October 2021 spec, section 6.4.4).
2024-01-31 15:59:07 -05:00
Riccardo Binetti
afa4ae66a0
improvement: return a map from decode_relay_id/1 (#107)
Slight API improvement over #106.

This makes it more ergonomic to partially match on the return value (and it also
makes it more explicit by explicitly labeling the two parts).

Also add tests for relay id encoding/decoding.
2024-01-25 10:47:15 -05:00
Riccardo Binetti
365b3aedc6
feat: Relay refetching support (#106)
* feat: add support for relay global IDs

* improvement: use the GraphQL type when projecting fields

This allows picking also up fields coming from fragments in queries returning an
interface

* feat: add relay node query

Allow retrieving a resource implementing the Node interface given its Relay
global id.
2024-01-24 14:59:12 -05:00
Zach Daniel
7225d5fd28 test: test loading through w/ nil values 2024-01-21 12:06:48 -05:00
Barnabas Jovanovics
772e3851ce
test: add better regression test (#101) 2023-11-24 07:24:27 -05:00
Barnabas Jovanovics
b9a3051e88
fix: make sure generic actions are authorized (#100) 2023-11-24 05:29:01 -05:00
Zach Daniel
e66a3ef4b8 fix: properly generate first aggregates with correct destination type 2023-11-13 23:02:57 -05:00
Zach Daniel
58a038e609 fix: generic action mutations need to use the input object 2023-10-02 19:44:19 -04:00
Zach Daniel
1950581f83 chore: attempt to fix an issue w/ incorrect action call 2023-09-17 19:17:13 -04:00
Zach Daniel
49c6534d73 improvement: generic action support
docs: better docs
2023-09-15 13:45:12 -04:00
Zach Daniel
0ec762507f test: fix testing type 2023-09-13 15:52:46 -04:00
Zach Daniel
1d69d8ef33 fix: support aggregates over calculations 2023-08-29 21:32:22 -04:00
Alan Heywood
0c869aa522
test: add failing test for an aggregate of a calculation (#92)
An error occurs at compile time:

== Compilation error in file test/support/schema.ex ==
** (MatchError) no match of right hand side value: {:error, "Must provide field type for max"}
    lib/resource/resource.ex:2278: AshGraphql.Resource.filterable?/2
    (elixir 1.15.4) lib/enum.ex:4265: Enum.filter_list/2
    (elixir 1.15.4) lib/enum.ex:4266: Enum.filter_list/2
    lib/resource/resource.ex:2229: AshGraphql.Resource.aggregate_filter_fields/2
    lib/resource/resource.ex:2195: AshGraphql.Resource.resource_filter_fields/2
    lib/resource/resource.ex:1159: AshGraphql.Resource.args/5
    lib/resource/resource.ex:425: anonymous fn/6 in AshGraphql.Resource.queries/5
    (elixir 1.15.4) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
2023-08-29 21:30:06 -04:00
Zach Daniel
39e33ca162 chore: fix testing type 2023-08-28 16:15:58 -04:00
Barnabas Jovanovics
bce89e985c
feat: add more sort order values (#91) 2023-08-28 10:42:39 -04:00
Barnabas Jovanovics
da1d1e889c
fix: wrap type in non-null reference if allow_nil? is set to false (#90)
* fix: wrap type in non-null reference if allow_nil? is set to false

* fix: get allow_nil? from the correct place
2023-08-22 14:43:27 -04:00
Zach Daniel
7e46a627b8 chore: format 2023-07-31 15:32:02 -04:00
Zach Daniel
fe85aab53a fix: properly display forbidden field errors
fixes #84
2023-07-13 09:23:17 -04:00
Barnabas Jovanovics
e11deb07aa
test: update field policy test (#83) 2023-07-13 08:46:26 -04:00
Zach Daniel
60517e6e20 chore: update tests, the fix is in main, just need to wait for release 2023-06-28 14:35:18 -04:00
Barnabas Jovanovics
14a5898958
test: add test for loading stuff through unions with fragments (#81) 2023-06-28 11:14:50 -04:00
Zach Daniel
d2f1f321f6 fix: handle detection of fields nested in aliases 2023-06-23 10:53:24 -04:00
Zach Daniel
bb96354470 improvement: support ForbiddenField 2023-06-23 10:10:39 -04:00