and in [PDF](https://gitlab.com/gitlab-org/create-stage/uploads/8e78ea7f326b2ef649e7d7d569c26d56/GraphQL_Deep_Dive__Create_.pdf).
and in [PDF](https://gitlab.com/gitlab-org/create-stage/uploads/8e78ea7f326b2ef649e7d7d569c26d56/GraphQL_Deep_Dive__Create_.pdf).
...
@@ -33,7 +33,7 @@ Authentication happens through the `GraphqlController`, right now this
...
@@ -33,7 +33,7 @@ Authentication happens through the `GraphqlController`, right now this
uses the same authentication as the Rails application. So the session
uses the same authentication as the Rails application. So the session
can be shared.
can be shared.
It is also possible to add a `private_token` to the querystring, or
It's also possible to add a `private_token` to the query string, or
add a `HTTP_PRIVATE_TOKEN` header.
add a `HTTP_PRIVATE_TOKEN` header.
## Global IDs
## Global IDs
...
@@ -75,7 +75,7 @@ The `iid`, `title` and `description` are _scalar_ GraphQL types.
...
@@ -75,7 +75,7 @@ The `iid`, `title` and `description` are _scalar_ GraphQL types.
When exposing a model through the GraphQL API, we do so by creating a
When exposing a model through the GraphQL API, we do so by creating a
new type in `app/graphql/types`. You can also declare custom GraphQL data types
new type in `app/graphql/types`. You can also declare custom GraphQL data types
for scalar data types (e.g.`TimeType`).
for scalar data types (for example`TimeType`).
When exposing properties in a type, make sure to keep the logic inside
When exposing properties in a type, make sure to keep the logic inside
the definition as minimal as possible. Instead, consider moving any
the definition as minimal as possible. Instead, consider moving any
...
@@ -760,6 +760,44 @@ to advertise the need for lookahead:
...
@@ -760,6 +760,44 @@ to advertise the need for lookahead:
For an example of real world use, please
For an example of real world use, please
see [`ResolvesMergeRequests`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/graphql/resolvers/concerns/resolves_merge_requests.rb).
see [`ResolvesMergeRequests`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/graphql/resolvers/concerns/resolves_merge_requests.rb).
## Pass a parent object into a child Presenter
Sometimes you need to access the resolved query parent in a child context to compute fields. Usually the parent is only
available in the `Resolver` class as `parent`.
To find the parent object in your `Presenter` class:
1. Add the parent object to the GraphQL `context` from within your resolver's `resolve` method:
```ruby
defresolve(**args)
context[:parent_object]=parent
end
```
1. Declare that your fields require the `parent` field context. For example:
```ruby
# in ChildType
field:computed_field,SomeType,null: true,
method: :my_computing_method,
extras: [:parent],# Necessary
description: 'My field description'
```
1. Declare your field's method in your Presenter class and have it accept the `parent` keyword argument.
This argument contains the parent **GraphQL context**, so you have to access the parent object with
`parent[:parent_object]` or whatever key you used in your `Resolver`:
```ruby
# in ChildPresenter
defmy_computing_method(parent:)
# do something with `parent[:parent_object]` here
end
```
For an example of real-world use, check [this MR that added `scopedPath` and `scopedUrl` to `IterationPresenter`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/39543)
## Mutations
## Mutations
Mutations are used to change any stored values, or to trigger
Mutations are used to change any stored values, or to trigger