Skip to content

Commit

Permalink
feat(core-server-graphql): Added core GraphQL Server implementation
Browse files Browse the repository at this point in the history
Updated libraries to use esbuild
  • Loading branch information
sullivanpj committed Sep 2, 2023
1 parent f25f273 commit ca2fa2e
Show file tree
Hide file tree
Showing 92 changed files with 15,404 additions and 29,353 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ HS_SERVICE_NAME="@open-system/repo"
# HS_DEBUG=true

SENTRY_ORGANIZATION="open-system"
SENTRY_PROPERTIES="apps/web/shell"

DEFAULT_LOCALE="en_US"
DEFAULT_TIMEZONE="America/New_York"

SENTRY_PROPERTIES="apps/web/shell"

CI_REPO_OWNER="sullivanpj"
CI_REPO_WORKER="🤖 Open-System Bot"
CI_REPO_NAME="open-system"
CI_BRANCH="main"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:
NX_VERBOSE_LOGGING: true
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
NX_CLOUD_AUTH_TOKEN: ${{ secrets.NX_CLOUD_AUTH_TOKEN }}
GITHUB_ACTOR: "🤖 Open System Bot"
GITHUB_ACTOR: "🤖 Open-System Bot"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ env:
CI: true
NX_DAEMON: false
NX_VERBOSE_LOGGING: true
GITHUB_ACTOR: "🤖 Open System Bot"
GITHUB_ACTOR: "🤖 Open-System Bot"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
NX_DAEMON: false
NX_VERBOSE_LOGGING: true
SKIP_ENV_VALIDATION: true
GITHUB_ACTOR: "🤖 Open System Bot"
GITHUB_ACTOR: "🤖 Open-System Bot"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
NX_DAEMON: false
NX_VERBOSE_LOGGING: true
SKIP_ENV_VALIDATION: true
GITHUB_ACTOR: "🤖 Open System Bot"
GITHUB_ACTOR: "🤖 Open-System Bot"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nextjs-bundle-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ env:
NX_DAEMON: false
NX_VERBOSE_LOGGING: true
SKIP_ENV_VALIDATION: true
GITHUB_ACTOR: "🤖 Open System Bot"
GITHUB_ACTOR: "🤖 Open-System Bot"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
13 changes: 12 additions & 1 deletion .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"automerge",
"avrogen",
"backlink",
"badkey",
"Benning",
"Bootstrapper",
"Buildable",
Expand All @@ -27,6 +28,7 @@
"corepack",
"cssmodule",
"cuid",
"Customizer",
"datamodel",
"Datasource",
"datasources",
Expand Down Expand Up @@ -64,6 +66,7 @@
"kysely",
"langium",
"Linq",
"macrotask",
"mediastream",
"Mediat",
"Mergeable",
Expand Down Expand Up @@ -146,7 +149,15 @@
"wundergraph",
"zenstack"
],
"enableFiletypes": ["txt", "js", "jsx", "ts", "tsx", "md", "mdx"],
"enableFiletypes": [
"txt",
"js",
"jsx",
"ts",
"tsx",
"md",
"mdx"
],
"ignorePaths": [
"**/.git/**",
"**/node_modules/**",
Expand Down
31 changes: 0 additions & 31 deletions libs/core/typescript/server/application/.swcrc

This file was deleted.

11 changes: 10 additions & 1 deletion libs/core/typescript/server/application/README.md
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 -->
10 changes: 8 additions & 2 deletions libs/core/typescript/server/application/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:swc",
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/core/typescript/server/application",
"tsConfig": "libs/core/typescript/server/application/tsconfig.lib.json",
"packageJson": "libs/core/typescript/server/application/package.json",
"main": "libs/core/typescript/server/application/src/index.ts",
"assets": ["libs/core/typescript/server/application/*.md"]
"assets": ["libs/core/typescript/server/application/*.md"],
"deleteOutputPath": true,
"bundle": true,
"metafile": true,
"minify": true,
"format": ["esm", "cjs"],
"platform": "node"
}
},
"lint": {
Expand Down
100 changes: 81 additions & 19 deletions libs/core/typescript/server/application/src/context/context.ts
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;
Loading

0 comments on commit ca2fa2e

Please sign in to comment.