@model-ts/graphql 7.2.0 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +15 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/Builder.js +4 -0
- package/dist/Builder.js.map +1 -1
- package/dist/Errors.d.ts +8 -0
- package/dist/Errors.d.ts.map +1 -1
- package/dist/Errors.js +8 -5
- package/dist/Errors.js.map +1 -1
- package/package.json +1 -1
- package/src/Builder.ts +4 -0
- package/src/Errors.ts +22 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @model-ts/graphql
|
|
2
2
|
|
|
3
|
+
## 7.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ce187d1: Add `where` to models, unions and `DynamoDB`: a pipe step that keeps a loaded item only when a predicate holds. After `load`, a rejected item fails with `ItemNotFoundError` for its key; after `loadOption` or any read of an `Option`, it becomes `Option.none()`.
|
|
8
|
+
|
|
9
|
+
Add `publicMessages` to `withErrorPolicy`: a public error with a fixed message reaches clients as only that message and its code, without its own message or declared fields.
|
|
10
|
+
|
|
3
11
|
## 7.2.0
|
|
4
12
|
|
|
5
13
|
## 7.1.0
|
package/README.md
CHANGED
|
@@ -1057,6 +1057,7 @@ Choose the public error code exposed to clients:
|
|
|
1057
1057
|
`examples/error-policy.ts`
|
|
1058
1058
|
|
|
1059
1059
|
```ts
|
|
1060
|
+
import { ItemNotFoundError } from "@model-ts/dynamodb"
|
|
1060
1061
|
import { createBuilder, ErrorReporter } from "@model-ts/graphql"
|
|
1061
1062
|
import { Cause, Effect, Layer, Schema } from "effect"
|
|
1062
1063
|
import type { AppContext, Types } from "../api/graphql.ts"
|
|
@@ -1065,8 +1066,12 @@ class AccessDenied extends Schema.TaggedError<AccessDenied>()("AccessDenied", {
|
|
|
1065
1066
|
message: Schema.String,
|
|
1066
1067
|
}) {}
|
|
1067
1068
|
export const GraphQL = createBuilder<Types, AppContext>().withErrorPolicy({
|
|
1068
|
-
public: [AccessDenied],
|
|
1069
|
-
publicCodes: {
|
|
1069
|
+
public: [AccessDenied, ItemNotFoundError],
|
|
1070
|
+
publicCodes: {
|
|
1071
|
+
AccessDenied: "ACCESS_DENIED",
|
|
1072
|
+
ItemNotFoundError: "NOT_FOUND",
|
|
1073
|
+
},
|
|
1074
|
+
publicMessages: { ItemNotFoundError: "Not found" },
|
|
1070
1075
|
})
|
|
1071
1076
|
export const Reporting = Layer.succeed(ErrorReporter, {
|
|
1072
1077
|
report: ({ cause, coordinate, phase }) =>
|
|
@@ -1087,6 +1092,14 @@ arbitrary thrown exception does not make it public. This policy also applies to
|
|
|
1087
1092
|
custom scalar callbacks and abstract-type resolution. Ordinary graphql-js
|
|
1088
1093
|
document diagnostics remain available to clients.
|
|
1089
1094
|
|
|
1095
|
+
Some errors are safe to report but carry fields that are not, such as the
|
|
1096
|
+
storage key of an `ItemNotFoundError`. Give their tag a fixed message in
|
|
1097
|
+
`publicMessages`: clients then get only that message and the error's code, here
|
|
1098
|
+
`{ message: "Not found", extensions: { code: "NOT_FOUND" } }`, and never the
|
|
1099
|
+
error's own message or fields. The keys must be tags of the `public` errors. A
|
|
1100
|
+
field that lists the error in its `errors` union still returns it as a union
|
|
1101
|
+
member with its declared fields.
|
|
1102
|
+
|
|
1090
1103
|
Provide `Reporting` alongside the application's service layers, for example with
|
|
1091
1104
|
`Layer.mergeAll(Sandbox.layerMemory(), Reporting)`. The optional `ErrorReporter`
|
|
1092
1105
|
receives the original Effect cause, field coordinate, and phase for masked
|