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: README.md
+26-9Lines changed: 26 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,17 @@ The `package.config` has been created with `start` and `watch` scripts. These us
19
19
### Functions
20
20
Any functions exported from `functions.ts` are made available as NDC functions/procedures to use in your Hasura metadata and expose as GraphQL fields in queries or mutation.
21
21
22
+
If you write a function that performs a read-only operation, you should mark it with the `@readonly` JSDoc tag, and it will be exposed as an NDC function, which will ultimately show up as a GraphQL query field in Hasura.
23
+
24
+
```typescript
25
+
/**@readonly*/
26
+
exportfunction add(x:number, y:number):number {
27
+
returnx+y;
28
+
}
29
+
```
30
+
31
+
Functions without the `@readonly` JSDoc tag are exposed as NDC procedures, which will ultimately show up as a GraphQL mutation field in Hasura.
32
+
22
33
Arguments to the function end up being field arguments in GraphQL and the return value is what the field will return when queried. Every function must return a value; `void`, `null` or `undefined` is not supported.
23
34
24
35
```typescript
@@ -136,18 +147,24 @@ These types are unsupported as function parameter types or return types for func
136
147
*[`void`](https://www.typescriptlang.org/docs/handbook/2/functions.html#void), [`object`](https://www.typescriptlang.org/docs/handbook/2/functions.html#object), [`unknown`](https://www.typescriptlang.org/docs/handbook/2/functions.html#unknown), [`never`](https://www.typescriptlang.org/docs/handbook/2/functions.html#never), [`any`](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any) types - to accept and return arbitrary JSON, use `sdk.JSONValue` instead
137
148
*`null` and `undefined` - unless used in a union with a single other type
138
149
139
-
140
-
### Impure/pure functions
141
-
If you write a function that performs a read-only operation, you should mark it with the `@readonly` JSDoc tag, and it will be exposed as an NDC function, which will ultimately show up as a GraphQL query field in Hasura.
142
-
143
-
```typescript
144
-
/**@readonly*/
145
-
exportfunction add(x:number, y:number):number {
146
-
returnx+y;
150
+
### Parallel execution
151
+
If functions are involved remote relationships in your Hasura metadata, then they may be queried in a [batch-based fashion](https://hasura.github.io/ndc-spec/specification/queries/variables.html). In this situation, any async functions that are marked with the `@readonly` JSDoc tag may be executed in parallel. The default degree of parallelism per query request to the connector is 10, but you may customise this by using the `@paralleldegree` JSDoc tag on your function.
152
+
153
+
```typescript
154
+
/**
155
+
* This function will only run up to 5 http requests in parallel per query
const result =awaitfetch("http://httpstat.us/${statusCode}")
162
+
const responseBody =awaitresult.json() asany;
163
+
returnresponseBody.description;
147
164
}
148
165
```
149
166
150
-
Functions without the `@readonly` JSDoc tag are exposed as NDC procedures, which will ultimately show up as a GraphQL mutation field in Hasura.
167
+
Non-readonly functions are not invoked in parallel within the same mutation request to the connector, so it is invalid to use the @paralleldegree JSDoc tag on those functions.
0 commit comments