@contractspec/lib.graphql-federation 1.44.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/LICENSE +21 -0
- package/README.md +69 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chaman Ventures, SASU
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @contractspec/lib.graphql-federation
|
|
2
|
+
|
|
3
|
+
Website: https://contractspec.io/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
GraphQL Federation utilities for Pothos.
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
To enable Apollo Federation support for Pothos schemas. This package configures the `@pothos/plugin-federation` and provides helpers for defining entities and resolving references.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @contractspec/lib.graphql-federation
|
|
16
|
+
# or
|
|
17
|
+
bun add @contractspec/lib.graphql-federation
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Key Concepts
|
|
21
|
+
|
|
22
|
+
- **Federation**: Apollo Federation V2 support.
|
|
23
|
+
- **Entities**: defining `key` fields and `resolveReference` methods.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { builder } from '@contractspec/lib.graphql-core';
|
|
29
|
+
import '@contractspec/lib.graphql-federation'; // Side-effect import to register plugin if needed, or use factory
|
|
30
|
+
|
|
31
|
+
builder.asEntity(User, {
|
|
32
|
+
key: builder.selection<{ id: string }>('id'),
|
|
33
|
+
resolveReference: (ref) => getUser(ref.id),
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SchemaTypes } from "@pothos/core";
|
|
2
|
+
import "@pothos/plugin-federation";
|
|
3
|
+
import { GraphQLSchema } from "graphql";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
declare function toSubgraphSDL(schema: GraphQLSchema): string;
|
|
7
|
+
declare function withEntityObject<T extends SchemaTypes>(builder: PothosSchemaTypes.SchemaBuilder<T>, name: string, keyFields: string[], fields: (t: any) => Record<string, any>, resolveReference: (ref: any, ctx: any) => Promise<any> | any): any;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { toSubgraphSDL, withEntityObject };
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;iBAKgB,aAAA,SAAsB;iBAItB,2BAA2B,sBAChC,iBAAA,CAAkB,cAAc,2DAGrB,+DACsB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "@pothos/core";
|
|
2
|
+
import "@pothos/plugin-federation";
|
|
3
|
+
import { printSubgraphSchema } from "@apollo/subgraph";
|
|
4
|
+
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
function toSubgraphSDL(schema) {
|
|
7
|
+
return printSubgraphSchema(schema);
|
|
8
|
+
}
|
|
9
|
+
function withEntityObject(builder, name, keyFields, fields, resolveReference) {
|
|
10
|
+
const ref = builder.objectRef(name);
|
|
11
|
+
ref.implement({ fields });
|
|
12
|
+
builder.entity(name, {
|
|
13
|
+
key: keyFields.join(" "),
|
|
14
|
+
resolveReference
|
|
15
|
+
});
|
|
16
|
+
return ref;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { toSubgraphSDL, withEntityObject };
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { type SchemaTypes } from '@pothos/core';\nimport '@pothos/plugin-federation';\nimport { printSubgraphSchema } from '@apollo/subgraph';\nimport type { GraphQLSchema } from 'graphql';\n\nexport function toSubgraphSDL(schema: GraphQLSchema) {\n return printSubgraphSchema(schema);\n}\n\nexport function withEntityObject<T extends SchemaTypes>(\n builder: PothosSchemaTypes.SchemaBuilder<T>,\n name: string,\n keyFields: string[],\n fields: (t: any) => Record<string, any>,\n resolveReference: (ref: any, ctx: any) => Promise<any> | any\n) {\n const ref = (builder as any).objectRef(name);\n ref.implement({\n fields,\n });\n (builder as any).entity(name, {\n key: keyFields.join(' '),\n resolveReference,\n });\n return ref;\n}\n"],"mappings":";;;;;AAKA,SAAgB,cAAc,QAAuB;AACnD,QAAO,oBAAoB,OAAO;;AAGpC,SAAgB,iBACd,SACA,MACA,WACA,QACA,kBACA;CACA,MAAM,MAAO,QAAgB,UAAU,KAAK;AAC5C,KAAI,UAAU,EACZ,QACD,CAAC;AACF,CAAC,QAAgB,OAAO,MAAM;EAC5B,KAAK,UAAU,KAAK,IAAI;EACxB;EACD,CAAC;AACF,QAAO"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contractspec/lib.graphql-federation",
|
|
3
|
+
"version": "1.44.0",
|
|
4
|
+
"description": "Pothos federation helpers and subgraph schema export utilities",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
13
|
+
"publish:pkg:canary": "bun publish:pkg --tag canary",
|
|
14
|
+
"build": "tsdown",
|
|
15
|
+
"dev": "tsup --watch",
|
|
16
|
+
"clean": "rm -rf dist"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@pothos/core": "^4.9.1",
|
|
20
|
+
"@pothos/plugin-federation": "^4.0.0",
|
|
21
|
+
"@pothos/plugin-directives": "^4.2.3",
|
|
22
|
+
"graphql": "^16.8.1",
|
|
23
|
+
"@apollo/subgraph": "^2.12.2"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"graphql": ">=16.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@contractspec/tool.typescript": "1.44.0",
|
|
30
|
+
"@contractspec/tool.tsdown": "1.44.0",
|
|
31
|
+
"tsdown": "^0.18.3",
|
|
32
|
+
"typescript": "^5.9.3"
|
|
33
|
+
},
|
|
34
|
+
"type": "module",
|
|
35
|
+
"module": "./dist/index.js",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": "./dist/index.js",
|
|
38
|
+
"./*": "./*"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"exports": {
|
|
43
|
+
".": "./dist/index.js",
|
|
44
|
+
"./*": "./*"
|
|
45
|
+
},
|
|
46
|
+
"registry": "https://registry.npmjs.org/"
|
|
47
|
+
},
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "https://github.com/lssm-tech/contractspec.git",
|
|
52
|
+
"directory": "packages/libs/graphql-federation"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://contractspec.io"
|
|
55
|
+
}
|