Skip to content

Commit

Permalink
chore: docs for custom queries
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Oct 9, 2024
1 parent 442dc13 commit 6fedbd7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions documentation/topics/custom-queries-and-mutations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Custom Queries & Mutations

You can define your own queries and mutations in your schema,
using Absinthe's tooling. See their docs for more.

If you want to return resource types defined by AshGraphql, however,
you will need to use `AshGraphql.load_fields/4` to ensure that any
requested fields are loaded.

For example:

```elixir
query do
field :custom_get_post, :post do
arg(:id, non_null(:id))

resolve(fn %{id: post_id}, resolution ->
with {:ok, post} when not is_nil(post) <- Ash.get(AshGraphql.Test.Post, post_id) do
AshGraphql.load_fields(post, AshGraphql.Test.Post, resolution)
end
end)
end
end
```
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ defmodule AshGraphql.MixProject do
"documentation/topics/graphql-generation.md",
"documentation/topics/modifying-the-resolution.md",
"documentation/topics/relay.md",
"documentation/topics/custom-queries-and-mutations.md",
"documentation/topics/upgrade.md",
"documentation/dsls/DSL:-AshGraphql.Domain.md",
"documentation/dsls/DSL:-AshGraphql.Resource.md",
Expand Down

0 comments on commit 6fedbd7

Please sign in to comment.