ash json api don't work with aggregates
I have a resource that has this aggregate:
If I add json api for that resource like this:
If I try to get that resource with
curl 'localhost:4000/api/markets/property'
I will get this error:
Which happens in the json_schema.ex:505
file.
This is what the agg
variable has at the time the error happens:
Which means that the function is called with: Aggregate.kind_to_type(:first, nil)
16 Replies
Thanks for the report! This is definitely a bug, can you log this on the asj_json_api GH repo and I'll address soon?
GitHub
Ash json api don't work with aggregates · Issue #69 · ash-project/a...
Describe the bug A read action will not work with JSON API if that action uses an aggregate. To Reproduce I have a resource that has this aggregate: aggregates do first :last_bid_price, :bids, :pri...
can you give
ash_json_api
main a shot?
LMK if it works
I pushed up a quick fix that I'm pretty sure will work 😆Seem to be working
🥳
but shouldn't my aggregate also come with the response? I can't see a last_bid_price field in the response
We don't include aggregates by default
you need to include
?fields=foo,bar,baz
and include the fields you want
which is a bit annoying, but thats how JSON:API
spec worksLike this?
http://localhost:4000/api/markets/property?fields=last_bid_price
and we can't reasonably include all fields by default because it might be expensive.
actually I think its
fields[type]=list
so fields[property]=last_bid_price,...all-the-rest
We can add an option to let you specify the default fields for a type at some pointSo, if I try this:
localhost:4000/api/markets/property?fields[property]=last_bid_price
It actually crashes in the server with:
lemme check
okay try main again
Seems to be working now! Kinda a pain that I will need to specify all the rest of the fields in this case, but it is part of the specification nothing related to ash
Yeah, agreed. We can potentially add our own logic to it, like add our own
add_fields[type]
that will keep the default
but that would just be in addition to the spec compliant behaviorA little bit off-topic, but in your opinion do you think the GraphQL library for Ash is more mature than the jsonAPI one?
significantly 🙂
Not because I think JSON:API is a worse choice
there are just a lot more people using ash_graphql
I will try that out then.
Either way thanks a lot for the fix 😁