Skip to content

Commit

Permalink
Add docs for @gqlField resolvers
Browse files Browse the repository at this point in the history
Summary: This diff adds some docs for the current state of the simplified syntax for property lookup resolvers. We may want to expand this into its own page in the future if we expand this to have more options and/or work on strong types but I think it fits in the current doc on defining fields.

Reviewed By: captbaritone

Differential Revision: D67425248

fbshipit-source-id: a4de39ad03b25f2cccd16efae6c5c365862941a1
  • Loading branch information
evanyeung authored and facebook-github-bot committed Dec 19, 2024
1 parent 330415e commit 29fb05b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions website/docs/guides/relay-resolvers/defining-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,42 @@ This is just a simple resolver that reads from the model type and returns a scal
* [Field Arguments](./field-arguments.md)
* [Live Fields](./live-fields.md)
* [Derived Fields](./derived-fields.md)

<FbInternalOnly>

## Simplified Syntax for Property Lookups

If you have a ["weak" type](./defining-types.md#defining-a-weak-type), you can easily define a simple resolver that just returns a property from the underlying model. For example, take a resolver being defined on the `UserModel` that looks like:
```tsx
/**
* @RelayResolver
*/
export function name(user: UserModel): string {
return user.name;
}
```

When defining the weak type, this resolver can by automatically generated by using a docblock with `@gqlField` over the field you want to expose.
```tsx
/**
* @RelayResolver
*/
export type UserModel = {
/**
* @gqlField
*/
name: string,
}
```
You can optionally include a description or `@deprecated` tag in the docblock
```tsx
/**
* @gqlField
* @deprecated Do not use this field anymore
*
* This is a description. Include more information
* about your field here.
*/
```
</FbInternalOnly>

0 comments on commit 29fb05b

Please sign in to comment.