@contractspec/lib.graphql-core 1.57.0 → 1.58.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/dist/browser/index.js +44 -0
- package/dist/index.d.ts +26 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -40
- package/dist/node/index.js +44 -0
- package/package.json +19 -12
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import SchemaBuilder from "@pothos/core";
|
|
3
|
+
import ComplexityPlugin from "@pothos/plugin-complexity";
|
|
4
|
+
import DataloaderPlugin from "@pothos/plugin-dataloader";
|
|
5
|
+
import RelayPlugin from "@pothos/plugin-relay";
|
|
6
|
+
import TracingPlugin, {
|
|
7
|
+
isRootField,
|
|
8
|
+
wrapResolver
|
|
9
|
+
} from "@pothos/plugin-tracing";
|
|
10
|
+
import { DateResolver, JSONResolver } from "graphql-scalars";
|
|
11
|
+
function createSchemaBuilder(options) {
|
|
12
|
+
const builder = new SchemaBuilder({
|
|
13
|
+
plugins: [RelayPlugin, ComplexityPlugin, TracingPlugin, DataloaderPlugin],
|
|
14
|
+
complexity: {
|
|
15
|
+
defaultComplexity: options.complexity?.defaultComplexity ?? 1,
|
|
16
|
+
defaultListMultiplier: options.complexity?.defaultListMultiplier ?? 10
|
|
17
|
+
},
|
|
18
|
+
tracing: {
|
|
19
|
+
default: (cfg) => options.tracing?.enableByDefault ?? true ? isRootField(cfg) : false,
|
|
20
|
+
wrap: (resolver, _opts, cfg) => wrapResolver(resolver, (_err, dur) => {
|
|
21
|
+
options.tracing?.onResolved?.(cfg.parentType, cfg.name, dur);
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
builder.addScalarType("JSON", JSONResolver);
|
|
26
|
+
builder.addScalarType("Date", DateResolver);
|
|
27
|
+
return builder;
|
|
28
|
+
}
|
|
29
|
+
var complexity = (value) => () => value;
|
|
30
|
+
var listComplexity = (base, multiplier = 10) => (_args, childComplexity) => base + multiplier * childComplexity;
|
|
31
|
+
function createLoggerTracing(logger, opLabel = "gql.field") {
|
|
32
|
+
return {
|
|
33
|
+
enableByDefault: true,
|
|
34
|
+
onResolved: (parentType, fieldName, durationMs) => {
|
|
35
|
+
logger.info(opLabel, { parentType, fieldName, durationMs });
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
listComplexity,
|
|
41
|
+
createSchemaBuilder,
|
|
42
|
+
createLoggerTracing,
|
|
43
|
+
complexity
|
|
44
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,34 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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;
|
|
1
|
+
export interface CreateBuilderOptions<C> {
|
|
2
|
+
contextType: C;
|
|
3
|
+
complexity?: {
|
|
4
|
+
defaultComplexity?: number;
|
|
5
|
+
defaultListMultiplier?: number;
|
|
6
|
+
};
|
|
7
|
+
tracing?: {
|
|
8
|
+
enableByDefault?: boolean;
|
|
9
|
+
onResolved?: (parentType: string, fieldName: string, durationMs: number) => void;
|
|
19
10
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
}
|
|
12
|
+
export declare function createSchemaBuilder<C extends {}>(options: CreateBuilderOptions<C>): PothosSchemaTypes.SchemaBuilder<PothosSchemaTypes.ExtendDefaultTypes<{
|
|
13
|
+
Context: C;
|
|
14
|
+
Scalars: {
|
|
15
|
+
JSON: {
|
|
16
|
+
Input: unknown;
|
|
17
|
+
Output: unknown;
|
|
18
|
+
};
|
|
19
|
+
Date: {
|
|
20
|
+
Input: Date;
|
|
21
|
+
Output: Date;
|
|
22
|
+
};
|
|
23
23
|
};
|
|
24
|
-
};
|
|
25
24
|
}>>;
|
|
26
|
-
declare const complexity: (value: number) => () => number;
|
|
27
|
-
declare const listComplexity: (base: number, multiplier?: number) => (_args: unknown, childComplexity: number) => number;
|
|
28
|
-
interface LoggerLike {
|
|
29
|
-
|
|
25
|
+
export declare const complexity: (value: number) => () => number;
|
|
26
|
+
export declare const listComplexity: (base: number, multiplier?: number) => (_args: unknown, childComplexity: number) => number;
|
|
27
|
+
export interface LoggerLike {
|
|
28
|
+
info: (msg: string, meta?: unknown) => void;
|
|
30
29
|
}
|
|
31
|
-
declare function createLoggerTracing(logger: LoggerLike, opLabel?: string): CreateBuilderOptions<unknown>["tracing"];
|
|
32
|
-
//#endregion
|
|
33
|
-
export { CreateBuilderOptions, LoggerLike, complexity, createLoggerTracing, createSchemaBuilder, listComplexity };
|
|
30
|
+
export declare function createLoggerTracing(logger: LoggerLike, opLabel?: string): CreateBuilderOptions<unknown>["tracing"];
|
|
34
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,WAAW,EAAE,CAAC,CAAC;IACf,UAAU,CAAC,EAAE;QACX,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAC;KAChC,CAAC;IACF,OAAO,CAAC,EAAE;QACR,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,UAAU,CAAC,EAAE,CACX,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,KACf,IAAI,CAAC;KACX,CAAC;CACH;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,EAAE,EAC9C,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC;aAGrB,CAAC;aACD;QACP,IAAI,EAAE;YAAE,KAAK,EAAE,OAAO,CAAC;YAAC,MAAM,EAAE,OAAO,CAAA;SAAE,CAAC;QAC1C,IAAI,EAAE;YAAE,KAAK,EAAE,IAAI,CAAC;YAAC,MAAM,EAAE,IAAI,CAAA;SAAE,CAAC;KACrC;IAqBJ;AAGD,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,iBAAgB,CAAC;AACzD,eAAO,MAAM,cAAc,GACxB,MAAM,MAAM,EAAE,mBAAe,MAC7B,OAAO,OAAO,EAAE,iBAAiB,MAAM,WACH,CAAC;AAGxC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CAC7C;AACD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,SAAc,GAMtE,oBAAoB,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAC9C"}
|
package/dist/index.js
CHANGED
|
@@ -1,49 +1,45 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/index.ts
|
|
1
3
|
import SchemaBuilder from "@pothos/core";
|
|
2
4
|
import ComplexityPlugin from "@pothos/plugin-complexity";
|
|
3
5
|
import DataloaderPlugin from "@pothos/plugin-dataloader";
|
|
4
6
|
import RelayPlugin from "@pothos/plugin-relay";
|
|
5
|
-
import TracingPlugin, {
|
|
7
|
+
import TracingPlugin, {
|
|
8
|
+
isRootField,
|
|
9
|
+
wrapResolver
|
|
10
|
+
} from "@pothos/plugin-tracing";
|
|
6
11
|
import { DateResolver, JSONResolver } from "graphql-scalars";
|
|
7
|
-
|
|
8
|
-
//#region src/index.ts
|
|
9
12
|
function createSchemaBuilder(options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
builder.addScalarType("JSON", JSONResolver);
|
|
29
|
-
builder.addScalarType("Date", DateResolver);
|
|
30
|
-
return builder;
|
|
13
|
+
const builder = new SchemaBuilder({
|
|
14
|
+
plugins: [RelayPlugin, ComplexityPlugin, TracingPlugin, DataloaderPlugin],
|
|
15
|
+
complexity: {
|
|
16
|
+
defaultComplexity: options.complexity?.defaultComplexity ?? 1,
|
|
17
|
+
defaultListMultiplier: options.complexity?.defaultListMultiplier ?? 10
|
|
18
|
+
},
|
|
19
|
+
tracing: {
|
|
20
|
+
default: (cfg) => options.tracing?.enableByDefault ?? true ? isRootField(cfg) : false,
|
|
21
|
+
wrap: (resolver, _opts, cfg) => wrapResolver(resolver, (_err, dur) => {
|
|
22
|
+
options.tracing?.onResolved?.(cfg.parentType, cfg.name, dur);
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
builder.addScalarType("JSON", JSONResolver);
|
|
27
|
+
builder.addScalarType("Date", DateResolver);
|
|
28
|
+
return builder;
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
var complexity = (value) => () => value;
|
|
31
|
+
var listComplexity = (base, multiplier = 10) => (_args, childComplexity) => base + multiplier * childComplexity;
|
|
34
32
|
function createLoggerTracing(logger, opLabel = "gql.field") {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
durationMs
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
};
|
|
33
|
+
return {
|
|
34
|
+
enableByDefault: true,
|
|
35
|
+
onResolved: (parentType, fieldName, durationMs) => {
|
|
36
|
+
logger.info(opLabel, { parentType, fieldName, durationMs });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
45
39
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
export {
|
|
41
|
+
listComplexity,
|
|
42
|
+
createSchemaBuilder,
|
|
43
|
+
createLoggerTracing,
|
|
44
|
+
complexity
|
|
45
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import SchemaBuilder from "@pothos/core";
|
|
3
|
+
import ComplexityPlugin from "@pothos/plugin-complexity";
|
|
4
|
+
import DataloaderPlugin from "@pothos/plugin-dataloader";
|
|
5
|
+
import RelayPlugin from "@pothos/plugin-relay";
|
|
6
|
+
import TracingPlugin, {
|
|
7
|
+
isRootField,
|
|
8
|
+
wrapResolver
|
|
9
|
+
} from "@pothos/plugin-tracing";
|
|
10
|
+
import { DateResolver, JSONResolver } from "graphql-scalars";
|
|
11
|
+
function createSchemaBuilder(options) {
|
|
12
|
+
const builder = new SchemaBuilder({
|
|
13
|
+
plugins: [RelayPlugin, ComplexityPlugin, TracingPlugin, DataloaderPlugin],
|
|
14
|
+
complexity: {
|
|
15
|
+
defaultComplexity: options.complexity?.defaultComplexity ?? 1,
|
|
16
|
+
defaultListMultiplier: options.complexity?.defaultListMultiplier ?? 10
|
|
17
|
+
},
|
|
18
|
+
tracing: {
|
|
19
|
+
default: (cfg) => options.tracing?.enableByDefault ?? true ? isRootField(cfg) : false,
|
|
20
|
+
wrap: (resolver, _opts, cfg) => wrapResolver(resolver, (_err, dur) => {
|
|
21
|
+
options.tracing?.onResolved?.(cfg.parentType, cfg.name, dur);
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
builder.addScalarType("JSON", JSONResolver);
|
|
26
|
+
builder.addScalarType("Date", DateResolver);
|
|
27
|
+
return builder;
|
|
28
|
+
}
|
|
29
|
+
var complexity = (value) => () => value;
|
|
30
|
+
var listComplexity = (base, multiplier = 10) => (_args, childComplexity) => base + multiplier * childComplexity;
|
|
31
|
+
function createLoggerTracing(logger, opLabel = "gql.field") {
|
|
32
|
+
return {
|
|
33
|
+
enableByDefault: true,
|
|
34
|
+
onResolved: (parentType, fieldName, durationMs) => {
|
|
35
|
+
logger.info(opLabel, { parentType, fieldName, durationMs });
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
listComplexity,
|
|
41
|
+
createSchemaBuilder,
|
|
42
|
+
createLoggerTracing,
|
|
43
|
+
complexity
|
|
44
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/lib.graphql-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.58.0",
|
|
4
4
|
"description": "Shared GraphQL core: Pothos builder factory, scalars, tracing & complexity",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contractspec",
|
|
@@ -18,9 +18,13 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
20
20
|
"publish:pkg:canary": "bun publish:pkg --tag canary",
|
|
21
|
-
"build": "
|
|
22
|
-
"dev": "
|
|
23
|
-
"clean": "rm -rf dist"
|
|
21
|
+
"build": "bun run prebuild && bun run build:bundle && bun run build:types",
|
|
22
|
+
"dev": "contractspec-bun-build dev",
|
|
23
|
+
"clean": "rm -rf dist",
|
|
24
|
+
"prebuild": "contractspec-bun-build prebuild",
|
|
25
|
+
"build:bundle": "contractspec-bun-build transpile",
|
|
26
|
+
"build:types": "contractspec-bun-build types",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
24
28
|
},
|
|
25
29
|
"dependencies": {
|
|
26
30
|
"@pothos/core": "^4.9.1",
|
|
@@ -35,21 +39,24 @@
|
|
|
35
39
|
"graphql": ">=16.0.0"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
38
|
-
"@contractspec/tool.typescript": "1.
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"typescript": "^5.9.3"
|
|
42
|
+
"@contractspec/tool.typescript": "1.58.0",
|
|
43
|
+
"typescript": "^5.9.3",
|
|
44
|
+
"@contractspec/tool.bun": "1.57.0"
|
|
42
45
|
},
|
|
43
46
|
"type": "module",
|
|
44
47
|
"exports": {
|
|
45
|
-
".": "./
|
|
46
|
-
"./*": "./*"
|
|
48
|
+
".": "./src/index.ts"
|
|
47
49
|
},
|
|
48
50
|
"publishConfig": {
|
|
49
51
|
"access": "public",
|
|
50
52
|
"exports": {
|
|
51
|
-
".":
|
|
52
|
-
|
|
53
|
+
".": {
|
|
54
|
+
"types": "./dist/index.d.ts",
|
|
55
|
+
"bun": "./dist/index.js",
|
|
56
|
+
"node": "./dist/node/index.mjs",
|
|
57
|
+
"browser": "./dist/browser/index.js",
|
|
58
|
+
"default": "./dist/index.js"
|
|
59
|
+
}
|
|
53
60
|
},
|
|
54
61
|
"registry": "https://registry.npmjs.org/"
|
|
55
62
|
},
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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":";;;;;;;;AA0BA,SAAgB,oBACd,SACA;CACA,MAAM,UAAU,IAAI,cAMjB;EACD,SAAS;GAAC;GAAa;GAAkB;GAAe;GAAiB;EACzE,YAAY;GACV,mBAAmB,QAAQ,YAAY,qBAAqB;GAC5D,uBAAuB,QAAQ,YAAY,yBAAyB;GACrE;EACD,SAAS;GACP,UAAU,QACP,QAAQ,SAAS,mBAAmB,OAAQ,YAAY,IAAI,GAAG;GAClE,OAAO,UAAU,OAAO,QACtB,aAAa,WAAW,MAAM,QAAQ;AACpC,YAAQ,SAAS,aAAa,IAAI,YAAY,IAAI,MAAM,IAAI;KAC5D;GACL;EACF,CAAC;AAEF,SAAQ,cAAc,QAAQ,aAAa;AAC3C,SAAQ,cAAc,QAAQ,aAAa;AAE3C,QAAO;;AAIT,MAAa,cAAc,gBAAwB;AACnD,MAAa,kBACV,MAAc,aAAa,QAC3B,OAAgB,oBACf,OAAO,aAAa;AAMxB,SAAgB,oBAAoB,QAAoB,UAAU,aAAa;AAC7E,QAAO;EACL,iBAAiB;EACjB,aAAa,YAAoB,WAAmB,eAAuB;AACzE,UAAO,KAAK,SAAS;IAAE;IAAY;IAAW;IAAY,CAAC;;EAE9D"}
|