@tinkerstack/graphql-annotation 0.0.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/.turbo/turbo-build.log +22 -0
- package/README.md +138 -0
- package/dist/index.d.mts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +511 -0
- package/dist/index.mjs +484 -0
- package/nest-cli.json +9 -0
- package/package.json +54 -0
- package/src/example/consumer/consumer.app.ts +38 -0
- package/src/example/consumer/consumer.example.ts +57 -0
- package/src/example/consumer/consumer.schema.gql +7 -0
- package/src/example/main.ts +23 -0
- package/src/example/producer/producer.app.ts +22 -0
- package/src/example/producer/producer.example.ts +28 -0
- package/src/example/producer/producer.schema.gql +20 -0
- package/src/index.ts +1 -0
- package/src/modules/core/annotation.constants.ts +37 -0
- package/src/modules/core/annotation.decorators.ts +147 -0
- package/src/modules/core/annotation.loader.ts +303 -0
- package/src/modules/core/annotation.module.ts +47 -0
- package/src/modules/core/annotation.resolver.ts +86 -0
- package/src/modules/core/annotation.utils.ts +48 -0
- package/src/modules/core/index.ts +4 -0
- package/src/modules/core/resolver.explorer.ts +31 -0
- package/src/modules/index.ts +1 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +30 -0
- package/tsup.config.ts +10 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { buildHTTPExecutor } from "@graphql-tools/executor-http";
|
|
2
|
+
import { schemaFromExecutor } from "@graphql-tools/wrap";
|
|
3
|
+
import type { SubschemaConfig } from "@graphql-tools/delegate";
|
|
4
|
+
|
|
5
|
+
export async function loadGraphQLSchema(url: string) {
|
|
6
|
+
const executor = buildHTTPExecutor({
|
|
7
|
+
endpoint: url,
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
schema: await schemaFromExecutor(executor),
|
|
11
|
+
executor, // Has to be included.
|
|
12
|
+
} as SubschemaConfig;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function split<TItem, TFilteredItem extends TItem = TItem>(
|
|
16
|
+
array: Array<TItem>,
|
|
17
|
+
predicate: (item: TItem) => item is TFilteredItem,
|
|
18
|
+
) {
|
|
19
|
+
const match = [] as TItem[];
|
|
20
|
+
const rest = [] as TItem[];
|
|
21
|
+
array.forEach((item) => {
|
|
22
|
+
const matchedPredicate = predicate(item);
|
|
23
|
+
const target = matchedPredicate ? match : rest;
|
|
24
|
+
target.push(item);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return [
|
|
28
|
+
match as TFilteredItem[],
|
|
29
|
+
rest as Exclude<TItem, TFilteredItem>[],
|
|
30
|
+
] as const;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function shallowMerge<TObj extends Record<string, any>[]>(
|
|
34
|
+
objects: [...TObj],
|
|
35
|
+
) {
|
|
36
|
+
type MergeObjectTuples<T> = T extends [infer THead, ...infer TRest]
|
|
37
|
+
? THead & MergeObjectTuples<TRest>
|
|
38
|
+
: unknown;
|
|
39
|
+
|
|
40
|
+
const res = {} as TObj;
|
|
41
|
+
objects.forEach((o) => Object.assign(res, o));
|
|
42
|
+
return res as MergeObjectTuples<TObj>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function isPlainObject(obj: any): obj is Record<PropertyKey, any> {
|
|
46
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
47
|
+
return prototype === Object.getPrototypeOf({}) || prototype === null;
|
|
48
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Injectable } from "@nestjs/common";
|
|
2
|
+
import { DiscoveryService } from "@nestjs/core";
|
|
3
|
+
import { InstanceWrapper } from "@nestjs/core/injector/instance-wrapper";
|
|
4
|
+
import { RESOLVER_TYPE_METADATA } from "@nestjs/graphql";
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class ResolverDiscoveryService {
|
|
8
|
+
constructor(
|
|
9
|
+
// NOTE: use `ModulesContainer` if robust module exclusion is needed
|
|
10
|
+
private readonly discoveryService: DiscoveryService,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
public explore() {
|
|
14
|
+
// Discovery logic is derived from https://github.com/nestjs/graphql/blob/51d3e1cbc827124a8b0e79370e26abfc5d9bd154/packages/graphql/lib/services/resolvers-explorer.service.ts#L47
|
|
15
|
+
const wrappedProviders = this.discoveryService.getProviders();
|
|
16
|
+
return wrappedProviders.flatMap((wrapped) => {
|
|
17
|
+
const { instance } = wrapped;
|
|
18
|
+
if (!instance) return []; // Otherwise will error on `getMetadata` due to `undefined`
|
|
19
|
+
|
|
20
|
+
// Don't get because the name can be `undefined`
|
|
21
|
+
// Not sure how on their lib still function even in case of `undefined`, probably in filtering
|
|
22
|
+
const isResolver = Reflect.hasMetadata(
|
|
23
|
+
RESOLVER_TYPE_METADATA,
|
|
24
|
+
instance.constructor,
|
|
25
|
+
);
|
|
26
|
+
if (!isResolver) return []; // Skip non-resolvers
|
|
27
|
+
|
|
28
|
+
return wrapped;
|
|
29
|
+
}) as InstanceWrapper[];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ts-node": {
|
|
3
|
+
"require": ["tsconfig-paths/register"] // configuration for typeorm migration
|
|
4
|
+
},
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"jsx": "react",
|
|
7
|
+
"module": "commonjs",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"removeComments": true,
|
|
10
|
+
"emitDecoratorMetadata": true,
|
|
11
|
+
"experimentalDecorators": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"target": "ES2022",
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"outDir": "./dist",
|
|
16
|
+
"baseUrl": "./",
|
|
17
|
+
"incremental": true,
|
|
18
|
+
"skipLibCheck": true,
|
|
19
|
+
"strictNullChecks": true,
|
|
20
|
+
"noImplicitAny": false,
|
|
21
|
+
"strictBindCallApply": false,
|
|
22
|
+
"forceConsistentCasingInFileNames": false,
|
|
23
|
+
"noFallthroughCasesInSwitch": false,
|
|
24
|
+
"esModuleInterop": true,
|
|
25
|
+
"importHelpers": true,
|
|
26
|
+
"paths": {
|
|
27
|
+
"@/*": ["src/*"]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|