mirror of
https://github.com/ent/ent.git
synced 2026-03-05 19:35:23 +03:00
doc/md: add the new CollectedFor annotation to graphql fields mapping (#4462)
See: https://github.com/ent/contrib/pull/623
This commit is contained in:
@@ -170,6 +170,25 @@ field.Int("category_id").
|
||||
)
|
||||
```
|
||||
|
||||
#### Collected For Resolver Fields
|
||||
|
||||
The `entgql.CollectedFor` annotation allows you to specify that a field should be automatically collected when certain
|
||||
GraphQL resolver fields (extended fields) are queried. This is useful when you have resolver fields that depend on
|
||||
underlying Ent field values.
|
||||
|
||||
```go
|
||||
field.String("name").
|
||||
Optional().
|
||||
Annotations(
|
||||
entgql.CollectedFor("uppercaseName"),
|
||||
)
|
||||
```
|
||||
|
||||
:::note
|
||||
If Ent does not know about the mapping between a resolver field and its underlying Ent field, and it encounters an unknown
|
||||
field in the query, it will query all fields from the database to ensure the resolver has the data it needs.
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
Well done! By using automatic field collection for our Ent schema definition, we were able to greatly improve the
|
||||
|
||||
Reference in New Issue
Block a user