Skip to content

Commit

Permalink
Merge pull request #276 from unigraph-dev/hotfix/init-fix
Browse files Browse the repository at this point in the history
hotfix(server): fix initialization
  • Loading branch information
thesophiaxu committed Dec 22, 2021
2 parents 23b4792 + 4da431a commit 16d448f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
10 changes: 8 additions & 2 deletions packages/unigraph-dev-backend/src/datamodelManager.ts
Expand Up @@ -20,9 +20,15 @@ export async function checkOrCreateDefaultDataModel(client: DgraphClient) {

if (unigraphObject.length < 1) {
// Insert default data
const tempSchemaCache = createSchemaCache(client);

await client.setSchema(defaultTypes);
await client.createUnigraphUpsert(insertsToUpsert([processAutorefUnigraphId({
"unigraph.id": "$/meta/namespace_map",
"$/schema/executable": { "unigraph.id": "$/schema/executable" },
"$/schema/package_manifest": { "unigraph.id": "$/schema/package_manifest" }
})]));

const tempSchemaCache = createSchemaCache(client);

for (let i=0; i<defaultUserlandSchemas.length; ++i) {
const schema = processAutorefUnigraphId(defaultUserlandSchemas[i]);
await client.createUnigraphUpsert(insertsToUpsert([schema], undefined, tempSchemaCache.dataAlt![0]));
Expand Down
2 changes: 1 addition & 1 deletion packages/unigraph-dev-backend/src/executableManager.ts
Expand Up @@ -87,7 +87,7 @@ export function buildExecutable(exec: Executable, context: ExecContext, unigraph
return ret;
}; else return fn;
}

if (Object.keys(environmentRunners).includes(exec.env) && (!exec.concurrency || states.runningExecutables.filter((el: any) => el.slug === exec["unigraph.id"]).length < exec.concurrency)) {
// @ts-expect-error: already checked for environment runner inclusion
return wrapExecutable(environmentRunners[exec.env](exec.src, context, unigraph));
Expand Down
1 change: 1 addition & 0 deletions packages/unigraph-dev-backend/src/hooks.ts
Expand Up @@ -44,6 +44,7 @@ export async function initEntityHeads (states: any, schemas: string[], client: D
}

export async function afterObjectCreatedHooks (states: any, hooks: Record<string, any[]>, client: DgraphClient) {
if (Object.keys(hooks).length === 0) return;
const queries = Object.keys(hooks).map((el, index) => `query${index} (func: eq(<unigraph.id>, "${el}")) {
uid
<~type> (after: ${states.entityHeadByType[el]}) {
Expand Down
13 changes: 7 additions & 6 deletions packages/unigraph-dev-backend/src/templates/defaultDb.ts
Expand Up @@ -10,6 +10,7 @@ import {pkg as coreuser} from 'unigraph-dev-common/lib/data/unigraph.coreuser.pk
import {pkg as execexample} from 'unigraph-dev-common/lib/data/unigraph.execexample.pkg';
import {pkg as calendar} from 'unigraph-dev-common/lib/data/unigraph.calendar.pkg';
import {pkg as notes} from 'unigraph-dev-common/lib/data/unigraph.notes.pkg';
import {pkg as contacts} from 'unigraph-dev-common/lib/data/unigraph.contacts.pkg';
import {pkg as home} from 'unigraph-dev-common/lib/data/unigraph.home.pkg';

// Userspace packages
Expand Down Expand Up @@ -45,6 +46,11 @@ type <Entity> {
_createdAt
_updatedAt
}
type <Named> {
type
_createdAt
_updatedAt
}
type <Type> {
_definition
}
Expand Down Expand Up @@ -314,14 +320,9 @@ export const defaultUserlandSchemas = [
},
packageManifestSchema,
packageExecutableSchema,
{
"unigraph.id": "$/meta/namespace_map",
"$/schema/executable": { "unigraph.id": "$/schema/executable" },
"$/schema/package_manifest": { "unigraph.id": "$/schema/package_manifest" }
},
]

export const defaultPackages = [
semantic, core, execexample, coreuser, home, calendar, notes,
semantic, core, execexample, coreuser, home, calendar, notes, contacts,
onboarding, todo, bookmark, rss_reader, email, reddit, twitter, nlp, openai, kanban
]

0 comments on commit 16d448f

Please sign in to comment.