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: docs/api/schema/resolvers.md
+45-20Lines changed: 45 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,6 +98,31 @@ Property resolver functions should only return a value and not have side effects
98
98
99
99
</BlockQuote>
100
100
101
+
## Virtual property resolvers
102
+
103
+
Virtual resolvers are property resolvers that do not use the `value` but instead always return a value of their own. The parameters are (`(data, context, status)`). The above example can be written like this:
Virtual resolvers should always be used when combined with a [database adapter](../databases/adapters.md) in order to make valid [$select queries](../databases/querying.md#select). Otherwise queries could try to select fields that do not exist in the database which will throw an error.
123
+
124
+
</BlockQuote>
125
+
101
126
## Options
102
127
103
128
A resolver takes the following options as the second parameter:
@@ -194,8 +219,14 @@ app.service('users').hooks({
194
219
195
220
Result resolvers use the `schemaHooks.resolveResult(...resolvers)` hook and resolve the data that is returned by a service call ([context.result](../hooks.md#context-result) in a hook). This can be used to populate associations or add other computed properties etc. It is possible to pass multiple resolvers which will run in the order they are passed, using the previous data. `schemaHooks.resolveResult` can be used as an `around` and `after` hook.
196
221
222
+
<BlockQuotetype="warning"label="Important">
223
+
224
+
Use as an `around` hook is recommended since this will ensure that database adapters will be able to handle [$select queries](../databases/querying.md#select) properly when using [virtual properties](#virtual-property-resolvers).
0 commit comments