Skip to content

Commit 4323071

Browse files
Rename @pure to @readonly
1 parent a62dc33 commit 4323071

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Any functions exported from `functions.ts` are made available as NDC functions/p
2222
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.
2323

2424
```typescript
25-
/** @pure */
25+
/** @readonly */
2626
export function hello(name: string, year: number): string {
2727
return `Hello ${name}, welcome to ${year}`
2828
}
@@ -130,16 +130,16 @@ These types are unsupported as function parameter types or return types for func
130130

131131

132132
### Impure/pure functions
133-
If you write a function that performs a read-only operation, or is otherwise a pure function (no side-effects), you can mark it with the `@pure` JSDoc tag, and it will be exposed as an NDC function, which will ultimately show up as a GraphQL query field in Hasura.
133+
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.
134134

135135
```typescript
136-
/** @pure */
136+
/** @readonly */
137137
export function add(x: number, y: number): number {
138138
return x + y;
139139
}
140140
```
141141

142-
Functions without the `@pure` JSDoc tag are exposed as NDC procedures, which will ultimately show up as a GraphQL mutation field in Hasura.
142+
Functions without the `@readonly` JSDoc tag are exposed as NDC procedures, which will ultimately show up as a GraphQL mutation field in Hasura.
143143

144144
## Deploying with `hasura3 connector create`
145145

ndc-lambda-sdk/src/inference.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function deriveFunctionSchema(functionDeclaration: ts.FunctionDeclaration, conte
167167
const functionType = context.typeChecker.getTypeOfSymbolAtLocation(functionSymbol, functionDeclaration);
168168

169169
const functionDescription = ts.displayPartsToString(functionSymbol.getDocumentationComment(context.typeChecker)).trim();
170-
const markedPureInJsDoc = functionSymbol.getJsDocTags().find(e => e.name === "pure") !== undefined;
170+
const markedReadonlyInJsDoc = functionSymbol.getJsDocTags().find(e => e.name === "readonly") !== undefined;
171171

172172
const functionCallSig = functionType.getCallSignatures()[0] ?? throwError(`Function '${functionName}' didn't have a call signature`)
173173
const functionSchemaArguments: Result<schema.ArgumentDefinition[], string[]> = Result.traverseAndCollectErrors(functionCallSig.getParameters(), paramSymbol => {
@@ -190,7 +190,7 @@ function deriveFunctionSchema(functionDeclaration: ts.FunctionDeclaration, conte
190190
const functionDefinition = Result.collectErrors(functionSchemaArguments, returnTypeResult)
191191
.map(([functionSchemaArgs, returnType]) => ({
192192
description: functionDescription ? functionDescription : null,
193-
ndcKind: markedPureInJsDoc ? schema.FunctionNdcKind.Function : schema.FunctionNdcKind.Procedure,
193+
ndcKind: markedReadonlyInJsDoc ? schema.FunctionNdcKind.Function : schema.FunctionNdcKind.Procedure,
194194
arguments: functionSchemaArgs,
195195
resultType: returnType
196196
}));

ndc-lambda-sdk/test/inference/basic-inference/simple-types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ export function hello(): string {
88
}
99

1010
/**
11-
* @pure
11+
* @readonly
1212
*/
1313
export function add(a: number, b: number): number {
1414
return a + b;
1515
}
1616

1717
/**
18-
* @pure
18+
* @readonly
1919
*/
2020
export function isEven(x: bigint): boolean {
2121
return x % 2n === 0n;
@@ -26,7 +26,7 @@ export function dateTime(): Date {
2626
}
2727

2828
/**
29-
* @pure
29+
* @readonly
3030
*/
3131
export function json(input: sdk.JSONValue): sdk.JSONValue {
3232
const jsonValue = input.value;

ndc-lambda-sdk/test/inference/external-dependencies/use-npm-package.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { emojify } from "node-emoji";
33

44
/**
5-
* @pure
5+
* @readonly
66
*/
77
export function useImportedPackage(s: string): string {
88
return emojify(`${s} :t-rex: :heart: NPM`);

yeoman-generator/src/app/templates/functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @pure Exposes the function as an NDC function (the function should only query data without making modifications)
2+
* @readonly Exposes the function as an NDC function (the function should only query data without making modifications)
33
*/
44
export function hello(name?: string) {
55
return `hello ${name ?? "world"}`;

0 commit comments

Comments
 (0)