Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Natoandro committed Dec 16, 2024
1 parent bba211e commit 5616d47
Show file tree
Hide file tree
Showing 23 changed files with 650 additions and 493 deletions.
11 changes: 11 additions & 0 deletions .ghjk/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .ghjk/lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@
"version-print": {
"ty": "denoFile@v1",
"key": "version-print",
"desc": "Print $METATYPE_VERSION",
"desc": "Print $CURRENT_VERSION",
"envKey": "bciqori26ml2iqph3izifvvfsf4b2ar3yddr344utbfstyk2v33ot3mq"
},
"test-rust": {
Expand Down
2 changes: 2 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions ghjk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

// @ts-nocheck: Deno file

import { METATYPE_VERSION, PUBLISHED_VERSION } from "./tools/consts.ts";
import {
CURRENT_VERSION,
LATEST_PRE_RELEASE_VERSION,
LATEST_RELEASE_VERSION,
} from "./tools/consts.ts";
import { file, ports, sedLock, semver, stdDeps } from "./tools/deps.ts";
import { validateVersions } from "./tools/tasks/lock.ts";
import installs from "./tools/installs.ts";
import tasks from "./tools/tasks/mod.ts";

Expand Down Expand Up @@ -116,11 +121,12 @@ env("dev")
ports.cargobi({ crateName: "git-cliff", locked: true }),
);

task("version-print", () => console.log(METATYPE_VERSION), {
desc: "Print $METATYPE_VERSION",
task("version-print", () => console.log(CURRENT_VERSION), {
desc: "Print $CURRENT_VERSION",
});

task("version-bump", async ($) => {
validateVersions();
const bumps = [
"major",
"premajor",
Expand All @@ -140,23 +146,25 @@ task("version-bump", async ($) => {

const newVersion = semver.format(
semver.increment(
semver.parse(METATYPE_VERSION),
semver.parse(CURRENT_VERSION),
bump as semver.ReleaseType,
{
prerelease: "rc",
},
),
);

$.logStep(`Bumping ${METATYPE_VERSION}${newVersion}`);
const lines = [[/^(export const METATYPE_VERSION = ").*(";)$/, newVersion]];
$.logStep(`Bumping ${CURRENT_VERSION}${newVersion}`);
const lines = [[/^(export const CURRENT_VERSION = ").*(";)$/, newVersion]];
if (bump === "prerelease") {
$.logStep(
`Bumping published version ${PUBLISHED_VERSION}${METATYPE_VERSION}`,
`Bumping published version ${
LATEST_PRE_RELEASE_VERSION || LATEST_RELEASE_VERSION
}${CURRENT_VERSION}`,
);
lines.push([
/^(export const PUBLISHED_VERSION = ").*(";)$/,
METATYPE_VERSION,
CURRENT_VERSION,
]);
}

Expand Down
3 changes: 3 additions & 0 deletions src/common/src/typegraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ pub struct TypeMeta {
pub version: String,
pub random_seed: Option<u32>,
pub artifacts: BTreeMap<PathBuf, Artifact>,
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub namespaces: Vec<u32>,
}

#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
Expand Down
9 changes: 5 additions & 4 deletions src/typegate/src/engine/planner/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,13 @@ export class Planner {
const inputType = this.tg.type(inputIdx, Type.OBJECT);
const argumentTypes = mapValues(
inputType.properties,
(idx, key) =>
this.tg.getGraphQLType(
(idx, key) => {
return this.tg.getGraphQLType(
this.tg.type(idx),
false,
inputType.id.includes(key),
),
inputType.id?.includes(key) ?? false,
);
},
);

const stage = this.createComputeStage(node, {
Expand Down
1 change: 1 addition & 0 deletions src/typegate/src/runtimes/deno/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export class DenoRuntime extends Runtime {
return [stage.withResolver(this.delegate(mat, verbose))];
}

console.log("root type", this.tg.types[0]);
if (this.tg.meta.namespaces!.includes(stage.props.typeIdx)) {
return [stage.withResolver(() => ({}))];
}
Expand Down
25 changes: 24 additions & 1 deletion src/typegate/src/transports/graphql/typegraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MPL-2.0

import type { TypeGraphDS } from "../../typegraph/mod.ts";
import type { ObjectNode } from "../../typegraph/type_node.ts";
import { type ObjectNode, Type } from "../../typegraph/type_node.ts";
import { addNode } from "./utils.ts";

type PropertiesTable = Record<string, number>;
Expand Down Expand Up @@ -123,3 +123,26 @@ export function parseGraphQLTypeGraph(tgOrig: TypeGraphDS): TypeGraphDS {

return typegraph;
}

// TEMPORARY
export function setNamespaces(tg: TypeGraphDS) {
if (tg.meta.namespaces != null) {
return;
}
const namespaces: number[] = [];

const rootNode = tg.types[0] as ObjectNode;

const addNamespacesFrom = (node: ObjectNode, nodeIdx: number) => {
namespaces.push(nodeIdx);
for (const [, typeIdx] of Object.entries(node.properties)) {
const childNode = tg.types[typeIdx];
if (childNode.type === Type.OBJECT) {
addNamespacesFrom(childNode, typeIdx);
}
}
};

addNamespacesFrom(rootNode, 0);
tg.meta.namespaces = namespaces;
}
21 changes: 12 additions & 9 deletions src/typegate/src/typegate/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import { handleGraphQL } from "../services/graphql_service.ts";
import { getLogger } from "../log.ts";
import { MigrationFailure } from "../runtimes/prisma/hooks/run_migrations.ts";
import { DenoFailure } from "../runtimes/deno/hooks/mod.ts";
import introspectionJson from "../typegraphs/introspection.json" with { type: "json" };
import introspectionJson from "../typegraphs/introspection.json" with {
type: "json",
};
import { ArtifactService } from "../services/artifact_service.ts";
import type { ArtifactStore } from "./artifacts/mod.ts";
// TODO move from tests (MET-497)
Expand Down Expand Up @@ -360,6 +362,7 @@ export class Typegate implements AsyncDisposable {
);

logger.info(`Registering engine '${name}'`);
logger.info("registering {}", this.register.constructor.name);
await this.register.add(engine);

const newArtifacts = new Set(
Expand Down Expand Up @@ -402,14 +405,14 @@ export class Typegate implements AsyncDisposable {

const introspection = enableIntrospection
? await TypeGraph.init(
this,
introspectionDef,
new SecretManager(introspectionDef, {}),
{
typegraph: TypeGraphRuntime.init(tgDS, [], {}),
},
null,
)
this,
introspectionDef,
new SecretManager(introspectionDef, {}),
{
typegraph: TypeGraphRuntime.init(tgDS, [], {}),
},
null,
)
: null;

const tg = await TypeGraph.init(
Expand Down
8 changes: 8 additions & 0 deletions src/typegate/src/typegate/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "../typegraph/versions.ts";
import { typegraphIdSchema, type TypegraphStore } from "../sync/typegraph.ts";
import { RedisReplicatedMap } from "../sync/replicated_map.ts";
import { setNamespaces } from "../transports/graphql/typegraph.ts";

export interface MessageEntry {
type: "info" | "warning" | "error";
Expand Down Expand Up @@ -60,6 +61,12 @@ export class ReplicatedRegister extends Register {
typegraphId,
);

// temparary hack
// FIXME why are namespaces not set??
if (tg.meta.namespaces == null) {
setNamespaces(tg);
}

// typegraph is updated while being pushed, this is only for initial load
const hasUpgrade = (initialLoad && isTypegraphUpToDate(tg)) || true;
console.log({ hasUpgrade });
Expand Down Expand Up @@ -97,6 +104,7 @@ export class ReplicatedRegister extends Register {
}

async add(engine: QueryEngine): Promise<void> {
console.debug("meta", engine.tg.tg.meta);
if (SystemTypegraph.check(engine.name)) {
// no need for a sync
this.replicatedMap.memory.set(engine.name, engine);
Expand Down
2 changes: 1 addition & 1 deletion src/typegate/src/typegraph/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export type ObjectNode = {
[k: string]: number;
};
required?: string[];
id: string[];
id?: string[];
};
export type ListNode = {
type: "list";
Expand Down
2 changes: 1 addition & 1 deletion src/typegate/src/typegraph/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const typegraphChangelog: Record<
const prop = x.types[typeIdx];
if ("injection" in prop) {
console.log({ injection: prop.injection, path });
throw new Error("injection");
// throw new Error("injection");
}
if (prop.type === Type.OBJECT) {
traverse(prop);
Expand Down
2 changes: 1 addition & 1 deletion src/typegraph/core/src/typegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ pub fn init(params: TypegraphInitParams) -> Result<()> {
dynamic: params.dynamic.unwrap_or(true),
endpoints: vec![],
},

cors: params.cors.into(),
auths: vec![],
prefix: params.prefix,
Expand All @@ -116,6 +115,7 @@ pub fn init(params: TypegraphInitParams) -> Result<()> {
outjection_secrets: vec![],
random_seed: Default::default(),
artifacts: Default::default(),
namespaces: Default::default(),
},
types: vec![],
saved_store_state: Some(Store::save()),
Expand Down
61 changes: 61 additions & 0 deletions tests/e2e/published/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { transformSyncConfig } from "@metatype/typegate/config.ts";
import { clearSyncData, setupSync } from "test-utils/hooks.ts";

const defaultSyncEnvs = {
// SYNC_REDIS_URL: "redis://:password@localhost:6379/12",
SYNC_S3_HOST: "http://localhost:9000",
SYNC_S3_REGION: "local",
SYNC_S3_ACCESS_KEY: "minio",
SYNC_S3_SECRET_KEY: "password",
// SYNC_S3_BUCKET: "upgrade-test",
SYNC_S3_PATH_STYLE: "true",
};

export function config(p: { redisDb: number; s3Bucket: string }) {
const syncEnvs = {
SYNC_REDIS_URL: `redis://:password@localhost:6379/${p.redisDb}`,
SYNC_S3_BUCKET: p.s3Bucket,
...defaultSyncEnvs,
};
const syncConfig = transformSyncConfig({
redis_url: new URL(syncEnvs.SYNC_REDIS_URL),
s3_host: new URL(syncEnvs.SYNC_S3_HOST),
s3_region: syncEnvs.SYNC_S3_REGION,
s3_access_key: syncEnvs.SYNC_S3_ACCESS_KEY,
s3_secret_key: syncEnvs.SYNC_S3_SECRET_KEY,
s3_bucket: syncEnvs.SYNC_S3_BUCKET,
s3_path_style: true,
});

return { syncConfig, syncEnvs };
}

export class Config {
syncEnvs: Record<string, string>;
syncConfig: ReturnType<typeof transformSyncConfig>;

constructor(redisDb: number, s3Bucket: string) {
this.syncEnvs = {
SYNC_REDIS_URL: `redis://:password@localhost:6379/${redisDb}`,
SYNC_S3_BUCKET: s3Bucket,
...defaultSyncEnvs,
};
this.syncConfig = transformSyncConfig({
redis_url: new URL(this.syncEnvs.SYNC_REDIS_URL),
s3_host: new URL(this.syncEnvs.SYNC_S3_HOST),
s3_region: this.syncEnvs.SYNC_S3_REGION,
s3_access_key: this.syncEnvs.SYNC_S3_ACCESS_KEY,
s3_secret_key: this.syncEnvs.SYNC_S3_SECRET_KEY,
s3_bucket: this.syncEnvs.SYNC_S3_BUCKET,
s3_path_style: true,
});
}

async clearSyncData() {
await clearSyncData(this.syncConfig);
}

async setupSync() {
await setupSync(this.syncConfig);
}
}
Loading

0 comments on commit 5616d47

Please sign in to comment.