@nxgt/shared-graphql 1.5.0 → 1.5.1
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/README.md +59 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,18 +4,31 @@ The GraphQL layer: Yoga + Hono wiring, the federation subgraph builder, shared
|
|
|
4
4
|
scalars and directives, dataloaders, subscriptions over Redis, upload handling,
|
|
5
5
|
and the SDL every service merges into its own schema.
|
|
6
6
|
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @nxgt/shared-graphql
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Public on npmjs; no token needed to install. TypeScript is a peer, pinned to
|
|
14
|
+
`^6.0.3` across every `@nxgt/*` package — the set is unsatisfiable if one of
|
|
15
|
+
them widens it. **`stx-sdk` is a required peer** (`>=1.1.0`).
|
|
16
|
+
|
|
7
17
|
## Subpaths
|
|
8
18
|
|
|
9
19
|
| Subpath | What is in it |
|
|
10
20
|
| --- | --- |
|
|
11
|
-
| `@nxgt/shared-graphql` | server wiring, scalars, utils, context types |
|
|
12
|
-
| `@nxgt/shared-graphql/security` |
|
|
21
|
+
| `@nxgt/shared-graphql` | server wiring, scalars, utils, context types, plugins |
|
|
22
|
+
| `@nxgt/shared-graphql/security` | `PolicyEvaluationService` / `evaluateFromRules` — wraps `@nxgt/security/policy` for a Yoga schema |
|
|
13
23
|
|
|
14
24
|
## The shared SDL ships in `graphql/`, not in `dist/`
|
|
15
25
|
|
|
16
26
|
`bun build` bundles code and nothing else, so the `.graphqls` files live in
|
|
17
|
-
their own published directory
|
|
18
|
-
|
|
27
|
+
their own published directory (`graphql/directives`, `graphql/scalars`,
|
|
28
|
+
`graphql/schema`). Point your codegen and your schema loader at
|
|
29
|
+
**`SHARED_SCHEMA_PATH`**, which this package resolves against its own root by
|
|
30
|
+
walking up to the nearest `package.json` — the bundle is `dist/index.js`, the
|
|
31
|
+
source is `src/utils/schema.utils.ts`, and no single relative path serves both.
|
|
19
32
|
|
|
20
33
|
```ts
|
|
21
34
|
import { loadTypeDefs, SCALAR_RESOLVERS, SHARED_SCHEMA_PATH } from '@nxgt/shared-graphql';
|
|
@@ -33,6 +46,15 @@ schema: ['./src/**/*.graphqls', SHARED_SCHEMA_PATH],
|
|
|
33
46
|
A relative path into this package's `src/` will not work from an install — it
|
|
34
47
|
is not published, and it was not there in the first place.
|
|
35
48
|
|
|
49
|
+
`SHARED_TYPE_DEFS` is a string of the shared directives (`@authenticated`,
|
|
50
|
+
`@policy`, `@shareable`, `@link`) plus empty root types. A subgraph that
|
|
51
|
+
builds through `buildSubgraphSchema` and never loads `SHARED_TYPE_DEFS` still
|
|
52
|
+
sees `@check`, because that declaration lives in `graphql/directives/` and
|
|
53
|
+
rides `SHARED_SCHEMA_PATH`. A directive put *only* in `SHARED_TYPE_DEFS`
|
|
54
|
+
would be invisible to exactly the schemas most likely to want it.
|
|
55
|
+
|
|
56
|
+
`buildSubgraphSchema` wraps Apollo's builder and prunes unused types.
|
|
57
|
+
|
|
36
58
|
## `@check` — the permission a field requires
|
|
37
59
|
|
|
38
60
|
`@authenticated` asks whether anyone is calling. `@policy` asks whether they
|
|
@@ -109,20 +131,44 @@ terms is vacuously true, so it would admit everyone while looking guarded.
|
|
|
109
131
|
A Keto outage is never a denial: `OryUnavailable` travels up to
|
|
110
132
|
`createMaskError`, which answers 503.
|
|
111
133
|
|
|
112
|
-
|
|
134
|
+
### A shipped directive is not a composed directive
|
|
135
|
+
|
|
136
|
+
Shipping the SDL is enough for a standalone Yoga schema. It is **not** enough
|
|
137
|
+
for a subgraph that federation composes. The day `@check` is used in `health`
|
|
138
|
+
or `platform`, rover needs both `@composeDirective(name: "@check")` in that
|
|
139
|
+
subgraph and the directive named in the subgraph's own `@link` import list.
|
|
140
|
+
Without them the composition drops it silently — the supergraph SDL comes out
|
|
141
|
+
valid, the field loses its check, and nothing fails.
|
|
142
|
+
|
|
143
|
+
## Plugins and context
|
|
144
|
+
|
|
145
|
+
| Export | What it does |
|
|
146
|
+
| --- | --- |
|
|
147
|
+
| `useOryAuth(ory)` | Yoga plugin: resolve the caller, set `context.user` |
|
|
148
|
+
| `useKetoChecks(ory)` | Yoga plugin: per-request DataLoader for Keto, and the `@check` transformer |
|
|
149
|
+
| `applyKetoChecks(schema)` | wrap an already-built schema with `@check` |
|
|
150
|
+
| `useAuth()` | Yoga plugin: require a user on the context |
|
|
151
|
+
| `extractJwtPlugin` | Apollo plugin: copy `request.extensions.payload` onto `context.jwt` |
|
|
113
152
|
|
|
114
153
|
`GraphQLBaseContext.user` is `TokenPrincipal` — the caller as the access token
|
|
115
154
|
describes them (`sub`, `uid`, `scope`). It is not `Principal`, which is the
|
|
116
155
|
header-derived shape used by the REST services.
|
|
117
156
|
|
|
118
|
-
`
|
|
157
|
+
`createYogaHono` / `honoYoga` (from this package's integrations) mount Yoga on
|
|
158
|
+
Hono. `sandboxExpolorer` serves Apollo Sandbox. Subscriptions go over Redis
|
|
159
|
+
(`graphql-subscriptions` is re-exported). `DataLoader` is re-exported so a
|
|
160
|
+
subgraph does not take a second copy.
|
|
119
161
|
|
|
120
|
-
|
|
162
|
+
Uploads: the `Upload` scalar lives in this package; `graphql/scalars` ships the
|
|
163
|
+
SDL.
|
|
121
164
|
|
|
122
|
-
|
|
123
|
-
bun add @nxgt/shared-graphql
|
|
124
|
-
```
|
|
165
|
+
## Things that bite
|
|
125
166
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
167
|
+
- **`@check` on a list field is the wrong tool.** Filter before the read.
|
|
168
|
+
- **Do not import `graphql-subscriptions` from `graphql-subscriptions`.** Take
|
|
169
|
+
it from this package, same reason mongoose comes from `@nxgt/shared-mongo`.
|
|
170
|
+
- **The sandbox helper is spelled `sandboxExpolorer`.** That is the export
|
|
171
|
+
name. A corrected spelling is a breaking change, not a typo fix in the
|
|
172
|
+
consumer.
|
|
173
|
+
- **`stx-sdk` is required.** Unlike `@nxgt/security`, this package does not
|
|
174
|
+
mark it optional.
|