@galaxy-stack/orbit-graphql-federation 0.1.5 → 0.1.7

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.
Files changed (3) hide show
  1. package/README.md +47 -0
  2. package/dist/index.js +493 -3101
  3. package/package.json +4 -4
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # @galaxy-stack/orbit-graphql-federation
2
+
3
+ Apollo Federation (v2) subgraph support for the Orbit GraphQL package — `@key` entities, `_service`/`_entities` federation queries, and directive generation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @galaxy-stack/orbit-graphql-federation @galaxy-stack/orbit-graphql graphql
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import 'reflect-metadata';
15
+ import { FederationSchemaBuilder } from '@galaxy-stack/orbit-graphql-federation';
16
+ import { Key, External, Provides } from '@galaxy-stack/orbit-graphql-federation';
17
+ import { GraphQLObjectType, GraphQLString } from 'graphql';
18
+
19
+ @Key('upc')
20
+ class Product {}
21
+
22
+ const builder = new FederationSchemaBuilder();
23
+ builder.registerEntity(Product, new GraphQLObjectType({
24
+ name: 'Product',
25
+ fields: { upc: { type: GraphQLString }, name: { type: GraphQLString } },
26
+ }));
27
+ builder.registerReferenceResolver('Product', async (rep) => {
28
+ return products.find((p) => p.upc === rep.upc) ?? null;
29
+ });
30
+
31
+ const schema = builder.buildSubgraphSchema();
32
+ // schema exposes _service { sdl } and _entities(representations)
33
+ ```
34
+
35
+ ## Federation directives
36
+
37
+ Class-level: `@Key(fields)`, `@Extends()`, `@Shareable()`, `@Inaccessible()`, `@Tag(name)`, `@Directive(sdl)`
38
+
39
+ Property-level: `@External()`, `@Requires(fields)`, `@Provides(fields)`, `@Shareable()`, `@Inaccessible()`, `@Override(from)`, `@Tag(name)`
40
+
41
+ Method-level: `@ResolveReference()` (alias `@ReferenceResolver()`)
42
+
43
+ ## Notes
44
+
45
+ - `_entities` stamps `__typename` on resolved entities so the `_Entity` union resolves even when reference resolvers omit it.
46
+ - `generateFederatedSDL` prints the federated schema (including `_service` and `_entities`), so entity-only subgraphs produce valid SDL.
47
+ - Object patterns accept both `{ service, rpc }` (GrpcMethod decorator contract) and `{ service, method }`.