@lssm/lib.graphql-core 0.0.0-canary-20251120170226
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 +41 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# @lssm/lib.graphql-core
|
|
2
|
+
|
|
3
|
+
Core GraphQL utilities and Pothos builder setup.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
To provide a pre-configured Pothos `SchemaBuilder` with common plugins (Complexity, Tracing, Relay, Dataloader) and standard scalar types. This ensures all GraphQL services in the monorepo start with a consistent baseline.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @lssm/lib.graphql-core
|
|
13
|
+
# or
|
|
14
|
+
bun add @lssm/lib.graphql-core
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Key Concepts
|
|
18
|
+
|
|
19
|
+
- **Shared Builder**: A factory or base builder configuration.
|
|
20
|
+
- **Scalars**: Common scalars like `DateTime`, `JSON`, etc.
|
|
21
|
+
- **Plugins**: Pre-wired plugins for performance and features.
|
|
22
|
+
|
|
23
|
+
## Exports
|
|
24
|
+
|
|
25
|
+
- `builder`: The configured Pothos builder factory.
|
|
26
|
+
- `scalars`: Re-exported scalars.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { builder } from '@lssm/lib.graphql-core';
|
|
32
|
+
|
|
33
|
+
builder.queryType({
|
|
34
|
+
fields: (t) => ({
|
|
35
|
+
hello: t.string({ resolve: () => 'world' }),
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const schema = builder.toSchema();
|
|
40
|
+
```
|
|
41
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
interface CreateBuilderOptions<C> {
|
|
3
|
+
contextType: C;
|
|
4
|
+
complexity?: {
|
|
5
|
+
defaultComplexity?: number;
|
|
6
|
+
defaultListMultiplier?: number;
|
|
7
|
+
};
|
|
8
|
+
tracing?: {
|
|
9
|
+
enableByDefault?: boolean;
|
|
10
|
+
onResolved?: (parentType: string, fieldName: string, durationMs: number) => void;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
declare function createSchemaBuilder<C extends {}>(options: CreateBuilderOptions<C>): PothosSchemaTypes.SchemaBuilder<PothosSchemaTypes.ExtendDefaultTypes<{
|
|
14
|
+
Context: C;
|
|
15
|
+
Scalars: {
|
|
16
|
+
JSON: {
|
|
17
|
+
Input: unknown;
|
|
18
|
+
Output: unknown;
|
|
19
|
+
};
|
|
20
|
+
Date: {
|
|
21
|
+
Input: Date;
|
|
22
|
+
Output: Date;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
}>>;
|
|
26
|
+
declare const complexity: (value: number) => () => number;
|
|
27
|
+
declare const listComplexity: (base: number, multiplier?: number) => (_args: unknown, childComplexity: number) => number;
|
|
28
|
+
interface LoggerLike {
|
|
29
|
+
info: (msg: string, meta?: unknown) => void;
|
|
30
|
+
}
|
|
31
|
+
declare function createLoggerTracing(logger: LoggerLike, opLabel?: string): CreateBuilderOptions<unknown>["tracing"];
|
|
32
|
+
//#endregion
|
|
33
|
+
export { CreateBuilderOptions, LoggerLike, complexity, createLoggerTracing, createSchemaBuilder, listComplexity };
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";UAUiB;EAAA,WAAA,EACF,CADE;EAgBD,UAAA,CAAA,EAAA;IACgB,iBAAA,CAAA,EAAA,MAAA;IAArB,qBAAA,CAAA,EAAA,MAAA;EAGE,CAAA;EAGQ,OAAA,CAAA,EAAA;IAAc,eAAA,CAAA,EAAA,OAAA;IAND,UAAA,CAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,SAAA,EAAA,MAAA,EAAA,UAAA,EAAA,MAAA,EAAA,GAAA,IAAA;EAAA,CAAA;;AA+BrB,iBAhCG,mBAgCwC,CAAA,UAAA,CAAA,CAAA,CAAA,CAAA,OAAA,EA/B7C,oBA+B6C,CA/BxB,CA+BwB,CAAA,CAAA,EA/BtB,iBAAA,CAAA,aA+BsB,CA/BtB,iBAAA,CAAA,kBA+BsB,CAAA;EAC3C,OAAA,EA7BA,CA6BA;EAMI,OAAA,EAAA;IAGD,IAAA,EAAA;;;;;aAnCK;cAAc;;;;cAyBtB;cACA;UAMI,UAAA;;;iBAGD,mBAAA,SAA4B,+BAMrC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"@pothos/core";import t from"@pothos/plugin-complexity";import n from"@pothos/plugin-dataloader";import r from"@pothos/plugin-relay";import i,{isRootField as a,wrapResolver as o}from"@pothos/plugin-tracing";import{DateResolver as s,JSONResolver as c}from"graphql-scalars";function l(l){let u=new e({plugins:[r,t,i,n],complexity:{defaultComplexity:l.complexity?.defaultComplexity??1,defaultListMultiplier:l.complexity?.defaultListMultiplier??10},tracing:{default:e=>l.tracing?.enableByDefault??!0?a(e):!1,wrap:(e,t,n)=>o(e,(e,t)=>{l.tracing?.onResolved?.(n.parentType,n.name,t)})}});return u.addScalarType(`JSON`,c),u.addScalarType(`Date`,s),u}const u=e=>()=>e,d=(e,t=10)=>(n,r)=>e+t*r;function f(e,t=`gql.field`){return{enableByDefault:!0,onResolved:(n,r,i)=>{e.info(t,{parentType:n,fieldName:r,durationMs:i})}}}export{u as complexity,f as createLoggerTracing,l as createSchemaBuilder,d as listComplexity};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import SchemaBuilder from '@pothos/core';\nimport ComplexityPlugin from '@pothos/plugin-complexity';\nimport DataloaderPlugin from '@pothos/plugin-dataloader';\nimport RelayPlugin from '@pothos/plugin-relay';\nimport TracingPlugin, {\n isRootField,\n wrapResolver,\n} from '@pothos/plugin-tracing';\nimport { DateResolver, JSONResolver } from 'graphql-scalars';\n\nexport interface CreateBuilderOptions<C> {\n contextType: C;\n complexity?: {\n defaultComplexity?: number;\n defaultListMultiplier?: number;\n };\n tracing?: {\n enableByDefault?: boolean;\n onResolved?: (\n parentType: string,\n fieldName: string,\n durationMs: number\n ) => void;\n };\n}\n\nexport function createSchemaBuilder<C extends {}>(\n options: CreateBuilderOptions<C>\n) {\n const builder = new SchemaBuilder<{\n Context: C;\n Scalars: {\n JSON: { Input: unknown; Output: unknown };\n Date: { Input: Date; Output: Date };\n };\n }>({\n plugins: [RelayPlugin, ComplexityPlugin, TracingPlugin, DataloaderPlugin],\n complexity: {\n defaultComplexity: options.complexity?.defaultComplexity ?? 1,\n defaultListMultiplier: options.complexity?.defaultListMultiplier ?? 10,\n },\n tracing: {\n default: (cfg) =>\n (options.tracing?.enableByDefault ?? true) ? isRootField(cfg) : false,\n wrap: (resolver, _opts, cfg) =>\n wrapResolver(resolver, (_err, dur) => {\n options.tracing?.onResolved?.(cfg.parentType, cfg.name, dur);\n }),\n },\n });\n\n builder.addScalarType('JSON', JSONResolver);\n builder.addScalarType('Date', DateResolver);\n\n return builder as typeof builder;\n}\n\n// Complexity helpers for consistent usage in field definitions\nexport const complexity = (value: number) => () => value;\nexport const listComplexity =\n (base: number, multiplier = 10) =>\n (_args: unknown, childComplexity: number) =>\n base + multiplier * childComplexity;\n\n// Tracing helper that integrates with a logger-like object\nexport interface LoggerLike {\n info: (msg: string, meta?: unknown) => void;\n}\nexport function createLoggerTracing(logger: LoggerLike, opLabel = 'gql.field') {\n return {\n enableByDefault: true,\n onResolved: (parentType: string, fieldName: string, durationMs: number) => {\n logger.info(opLabel, { parentType, fieldName, durationMs });\n },\n } as CreateBuilderOptions<unknown>['tracing'];\n}\n"],"mappings":"6RA0BA,SAAgB,EACd,EACA,CACA,IAAM,EAAU,IAAI,EAMjB,CACD,QAAS,CAAC,EAAa,EAAkB,EAAe,EAAiB,CACzE,WAAY,CACV,kBAAmB,EAAQ,YAAY,mBAAqB,EAC5D,sBAAuB,EAAQ,YAAY,uBAAyB,GACrE,CACD,QAAS,CACP,QAAU,GACP,EAAQ,SAAS,iBAAmB,GAAQ,EAAY,EAAI,CAAG,GAClE,MAAO,EAAU,EAAO,IACtB,EAAa,GAAW,EAAM,IAAQ,CACpC,EAAQ,SAAS,aAAa,EAAI,WAAY,EAAI,KAAM,EAAI,EAC5D,CACL,CACF,CAAC,CAKF,OAHA,EAAQ,cAAc,OAAQ,EAAa,CAC3C,EAAQ,cAAc,OAAQ,EAAa,CAEpC,EAIT,MAAa,EAAc,OAAwB,EACtC,GACV,EAAc,EAAa,MAC3B,EAAgB,IACf,EAAO,EAAa,EAMxB,SAAgB,EAAoB,EAAoB,EAAU,YAAa,CAC7E,MAAO,CACL,gBAAiB,GACjB,YAAa,EAAoB,EAAmB,IAAuB,CACzE,EAAO,KAAK,EAAS,CAAE,aAAY,YAAW,aAAY,CAAC,EAE9D"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lssm/lib.graphql-core",
|
|
3
|
+
"version": "0.0.0-canary-20251120170226",
|
|
4
|
+
"description": "Shared GraphQL core: Pothos builder factory, scalars, tracing & complexity",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsdown",
|
|
13
|
+
"dev": "tsup --watch",
|
|
14
|
+
"clean": "rm -rf dist"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@pothos/core": "^4.9.1",
|
|
18
|
+
"@pothos/plugin-complexity": "^4.1.2",
|
|
19
|
+
"@pothos/plugin-dataloader": "^4.4.2",
|
|
20
|
+
"@pothos/plugin-relay": "^4.4.3",
|
|
21
|
+
"@pothos/plugin-tracing": "^1.1.2",
|
|
22
|
+
"graphql": "^16.8.1",
|
|
23
|
+
"graphql-scalars": "^1.22.5"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"graphql": ">=16.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@lssm/tool.tsdown": "0.0.0-canary-20251120170226",
|
|
30
|
+
"tsdown": "^0.15.9",
|
|
31
|
+
"typescript": "^5.9.3"
|
|
32
|
+
},
|
|
33
|
+
"type": "module",
|
|
34
|
+
"module": "./dist/index.js",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": "./dist/index.js",
|
|
37
|
+
"./*": "./*"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"exports": {
|
|
41
|
+
".": "./dist/index.js",
|
|
42
|
+
"./*": "./*"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|