-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core-server-graphql): Added core GraphQL Server implementation
Updated libraries to use esbuild
- Loading branch information
1 parent
f25f273
commit ca2fa2e
Showing
92 changed files
with
15,404 additions
and
29,353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
# core-server-application | ||
<!-- START header --> | ||
<!-- END header --> | ||
|
||
# Core Application-Level Library (Server) | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
<!-- START doctoc --> | ||
<!-- END doctoc --> | ||
|
||
## Building | ||
|
||
Run `nx build core-server-application` to build the library. | ||
|
||
## Running unit tests | ||
|
||
Run `nx test core-server-application` to execute the unit tests via [Jest](https://jestjs.io). | ||
|
||
<!-- START footer --> | ||
<!-- END footer --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 81 additions & 19 deletions
100
libs/core/typescript/server/application/src/context/context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,102 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
import { EnvManager } from "@open-system/core-shared-env"; | ||
import { IEntity } from "@open-system/core-server-domain/types"; | ||
import { Injector } from "@open-system/core-shared-injection"; | ||
import { Injector as InjectorInterface } from "@open-system/core-shared-injection/types"; | ||
import { Logger, UniqueIdGenerator } from "@open-system/core-shared-utilities"; | ||
import { BaseServerContext, ServerContext, UserContext } from "../types"; | ||
import { | ||
ArrayElement, | ||
Logger, | ||
UniqueIdGenerator | ||
} from "@open-system/core-shared-utilities"; | ||
import { | ||
CreateServerContextParams, | ||
ServerContext, | ||
UserContext, | ||
WhereParams, | ||
WhereUniqueParams | ||
} from "../types"; | ||
|
||
export const createContext = <TUser extends UserContext = UserContext>({ | ||
export const createServerContext = < | ||
TUser extends UserContext = UserContext, | ||
TEntities extends Array<IEntity> = Array<IEntity>, | ||
TNamespace extends ArrayElement<TEntities>["__typename"] = ArrayElement<TEntities>["__typename"], | ||
TEntityMapping extends Record<TNamespace, ArrayElement<TEntities>> = Record< | ||
TNamespace, | ||
ArrayElement<TEntities> | ||
>, | ||
TSelectKeys extends Record< | ||
TNamespace, | ||
| WhereParams<TEntityMapping[TNamespace], keyof TEntityMapping[TNamespace]> | ||
| WhereUniqueParams< | ||
TEntityMapping[TNamespace], | ||
keyof TEntityMapping[TNamespace] | ||
> | ||
| Record<string, never> | ||
> = Record< | ||
TNamespace, | ||
| WhereParams<TEntityMapping[TNamespace], keyof TEntityMapping[TNamespace]> | ||
| WhereUniqueParams< | ||
TEntityMapping[TNamespace], | ||
keyof TEntityMapping[TNamespace] | ||
> | ||
| Record<string, never> | ||
>, | ||
TCacheKeys = TSelectKeys, | ||
TServerContext extends ServerContext< | ||
TUser, | ||
TEntities, | ||
TNamespace, | ||
TEntityMapping, | ||
TSelectKeys, | ||
TCacheKeys | ||
> = ServerContext< | ||
TUser, | ||
TEntities, | ||
TNamespace, | ||
TEntityMapping, | ||
TSelectKeys, | ||
TCacheKeys | ||
> | ||
>({ | ||
correlationId, | ||
requestId, | ||
headers = {}, | ||
environment, | ||
logger, | ||
env, | ||
user, | ||
injector | ||
}: { | ||
correlationId?: string; | ||
logger?: Logger; | ||
user?: TUser; | ||
env: EnvManager; | ||
injector: InjectorInterface; | ||
}): ServerContext<TUser> => { | ||
injector, | ||
service | ||
}: CreateServerContextParams<TUser>): TServerContext => { | ||
const _injector = injector ?? Injector; | ||
|
||
return { | ||
correlationId: correlationId ? correlationId : UniqueIdGenerator.generate(), | ||
requestId: requestId ? requestId : UniqueIdGenerator.generate(), | ||
headers, | ||
environment: environment ?? env.environment, | ||
logger: logger ?? _injector.get(Logger), | ||
env, | ||
injector: _injector, | ||
user: { id: UniqueIdGenerator.generate(), ...user } as TUser | ||
}; | ||
user: { id: UniqueIdGenerator.generate(), ...user } as TUser, | ||
service: { | ||
...service, | ||
instanceId: service.instanceId ?? UniqueIdGenerator.generate() | ||
}, | ||
repositories: {} | ||
} as TServerContext; | ||
}; | ||
|
||
export const extractCorrelationId = (context?: BaseServerContext) => | ||
export const extractCorrelationId = (context?: ServerContext) => | ||
context?.correlationId; | ||
|
||
export const extractLogger = (context?: BaseServerContext) => context?.logger; | ||
export const extractRequestId = (context?: ServerContext) => context?.requestId; | ||
|
||
export const extractUser = (context?: BaseServerContext) => context?.user; | ||
export const extractHeaders = (context?: ServerContext) => context?.headers; | ||
|
||
export const extractUserId = (context?: BaseServerContext) => context?.user?.id; | ||
export const extractLogger = (context?: ServerContext) => context?.logger; | ||
|
||
export const extractUser = (context?: ServerContext) => context?.user; | ||
|
||
export const extractUserId = (context?: ServerContext) => context?.user?.id; | ||
|
||
export const extractService = (context?: ServerContext) => context?.service; |
Oops, something went wrong.