You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#### In our case we allow client to fetch all products
709
+
```
698
710
699
711
#### `Attention!` Query fields resolvers should always return the instance of object or an collection of objects the field type expects or nil if allowed.
700
712
@@ -704,54 +716,73 @@ You can get an access to field arguments in resolver using second argument (args
704
716
705
717
```graphql
706
718
query {
707
-
products {
719
+
product(id: 10) {
708
720
id
709
-
title
710
-
price
721
+
name
711
722
}
712
723
}
713
724
```
714
725
715
726
```json
716
727
{
717
728
"data": {
718
-
"products": [
719
-
{
720
-
"id:": "uniqueProductId",
721
-
"title": "Sandwitch",
722
-
"price": 1.0
723
-
},
724
-
...
725
-
]
729
+
"product": {
730
+
"id": 10,
731
+
"name": "..."
732
+
}
726
733
}
727
734
}
735
+
728
736
```
729
737
730
738
---
731
739
732
740
## Mutations
733
741
734
-
### Mutations are queries with side effects. Mutations are used to mutate your data. In order to use mutations you need to define a mutation root type that allows for defining fields that can mutate your data.
742
+
####Mutations are queries with side effects. Mutations are used to mutate your data. In order to use mutations you need to define a mutation root type that allows for defining fields that can mutate your data.
735
743
736
-
### Then add your mutations here:
744
+
`app/graphql/types/mutation_type.rb`
737
745
738
746
```ruby
739
-
# app/graphql/types/mutation_type.rb
740
-
Types::MutationType=GraphQL::ObjectType.define do
741
-
name "Mutation"
747
+
classTypes::MutationType < ::Types::Base::Object
748
+
description '...'
742
749
743
-
field :addTask, Types::TaskTypedo
744
-
description "Adds a task to list"
750
+
field :product_create, mutation:Mutations::Product::Create
0 commit comments