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
Copy file name to clipboardExpand all lines: website/docs/guides/relay-resolvers/return-types.md
+32Lines changed: 32 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -109,6 +109,38 @@ function Post() {
109
109
}
110
110
```
111
111
112
+
##Abstract Types
113
+
114
+
Resolvers may return some permutations of "abstract" types (GraphQL unions and interfaces). To use this feature simply use the abstract type's name in the docblock field description and include the typename in the object returned from your resolver. For "strong" types, that will look like:`{id: DataID, __typename: string}`. For "weak" types that will look like:`{__relay_model_instance: T, __typename: string}`.
Relay will generate type assertions to ensure your resolver function returns the expected type. However, not all combinations are supported. For example, Relay does not yet support the following permutations of abstract types: Unions including weak types, abstract types which mix strong add weak types, and abstract types which include server-backed types.
130
+
:::
131
+
132
+
While abstract types themselves cannot be defined using Resolver syntax today, you may define interfaces and unions, as well as their members, using[Client Schema Extensions](../client-schema-extensions.md). For example:
133
+
134
+
```graphql title="client-schema.graphql"
135
+
interfaceAnimal {
136
+
legs:Int
137
+
}
138
+
139
+
extendtypeCatimplementsAnimal {
140
+
__do_not_use:String # Placeholder because GraphQL does not allow empty field sets.
141
+
}
142
+
```
143
+
112
144
## JavaScript Values
113
145
114
146
TherearerarecaseswhereyouwanttoreturnanarbitraryJavaScriptvaluefromyourResolverschema, one which cannot not have a corresponding GraphQL type. As an escape hatch Relay supports a custom return type `RelayResolverValue` that allows you to return any JavaScript value from your resolver. **JavaScript values returned from resolvers should be immutable.**