Skip to content

Commit bfe8b30

Browse files
committed
chore: update getting started to prefer domain definition
1 parent a31de26 commit bfe8b30

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

documentation/tutorials/getting-started-with-graphql.md

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -132,48 +132,10 @@ use AshGraphql, domains: [Your.Domain1, Your.Domain2]
132132
133133
Some example queries/mutations are shown below. If no queries/mutations are added, nothing will show up in the GraphQL API, so be sure to set one up if you want to try it out.
134134
135-
### Queries & Mutations on the Resource
136-
137-
Here we show queries and mutations being added to the resource, but you can also define them on the _domain_. See below for an equivalent definition
138-
139-
```elixir
140-
defmodule Helpdesk.Support.Ticket do
141-
use Ash.Resource,
142-
...,
143-
extensions: [
144-
AshGraphql.Resource
145-
]
146-
147-
graphql do
148-
type :ticket
149-
150-
queries do
151-
# Examples
152-
153-
# create a field called `get_ticket` that uses the `read` read action to fetch a single ticke
154-
get :get_ticket, :read
155-
# create a field called `most_important_ticket` that uses the `most_important` read action to fetch a single record
156-
read_one :most_important_ticket, :most_important
157-
158-
# create a field called `list_tickets` that uses the `read` read action to fetch a list of tickets
159-
list :list_tickets, :read
160-
end
161-
162-
mutations do
163-
# Examples
164-
165-
create :create_ticket, :create
166-
update :update_ticket, :update
167-
destroy :destroy_ticket, :destroy
168-
end
169-
end
170-
171-
...
172-
end
173-
```
174-
175135
### Queries & Mutations on the Domain
176136
137+
Here we show queries and mutations being added to the domain, but you can also define them on the resource. See below for an equivalent definition. Prefer to add to the domain so your interface is defined in one place.
138+
177139
```elixir
178140
defmodule Helpdesk.Support.Ticket do
179141
use Ash.Resource,
@@ -216,6 +178,44 @@ defmodule Helpdesk.Support do
216178
end
217179
```
218180
181+
### Queries & Mutations on the Resource
182+
183+
```elixir
184+
defmodule Helpdesk.Support.Ticket do
185+
use Ash.Resource,
186+
...,
187+
extensions: [
188+
AshGraphql.Resource
189+
]
190+
191+
graphql do
192+
type :ticket
193+
194+
queries do
195+
# Examples
196+
197+
# create a field called `get_ticket` that uses the `read` read action to fetch a single ticke
198+
get :get_ticket, :read
199+
# create a field called `most_important_ticket` that uses the `most_important` read action to fetch a single record
200+
read_one :most_important_ticket, :most_important
201+
202+
# create a field called `list_tickets` that uses the `read` read action to fetch a list of tickets
203+
list :list_tickets, :read
204+
end
205+
206+
mutations do
207+
# Examples
208+
209+
create :create_ticket, :create
210+
update :update_ticket, :update
211+
destroy :destroy_ticket, :destroy
212+
end
213+
end
214+
215+
...
216+
end
217+
```
218+
219219
## What's next?
220220

221221
Topics:

0 commit comments

Comments
 (0)