Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/typesync/src/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,21 @@ export function buildMappingFile(schema: Domain.InsertAppSchema) {
const typeMappings: string[] = [];

for (const type of schema.types) {
// Skip types without a valid knowledgeGraphId
if (!type.knowledgeGraphId) {
continue;
}

const properties: string[] = [];
const relations: string[] = [];

// Process properties and relations
for (const property of type.properties) {
// Skip properties without a valid knowledgeGraphId
if (!property.knowledgeGraphId) {
continue;
}

if (Domain.isDataTypeRelation(property.dataType)) {
// This is a relation
relations.push(` ${Utils.toCamelCase(property.name)}: Id.Id('${property.knowledgeGraphId}')`);
Expand Down
124 changes: 124 additions & 0 deletions apps/typesync/test/Generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,128 @@ export const mapping: Mapping = {
});
expect(mapping).toBe(expectedMapping);
});

it('should skip a type entry without a knowledgeGraphId', () => {
const expectedMapping = `import { Id } from '@graphprotocol/grc-20';
import type { Mapping } from '@graphprotocol/hypergraph';

export const mapping: Mapping = {
Space: {
typeIds: [Id.Id('362c1dbd-dc64-44bb-a3c4-652f38a642d7')],
properties: {
name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'),
description: Id.Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'),
},
},
};`;

const mapping = buildMappingFile({
name: 'test',
description: 'test',
directory: 'test',
template: 'vite_react',
types: [
{
name: 'Space',
knowledgeGraphId: '362c1dbd-dc64-44bb-a3c4-652f38a642d7',
properties: [
{
name: 'Name',
knowledgeGraphId: 'a126ca53-0c8e-48d5-b888-82c734c38935',
dataType: 'Text',
},
{
name: 'Description',
knowledgeGraphId: '9b1f76ff-9711-404c-861e-59dc3fa7d037',
dataType: 'Text',
},
],
},
{
name: 'new type',
knowledgeGraphId: null,
properties: [
{
name: 'new prop',
knowledgeGraphId: null,
dataType: 'Text',
},
],
},
],
});
expect(mapping).toBe(expectedMapping);
});

it('should skip a property entry without a knowledgeGraphId', () => {
const expectedMapping = `import { Id } from '@graphprotocol/grc-20';
import type { Mapping } from '@graphprotocol/hypergraph';

export const mapping: Mapping = {
Space: {
typeIds: [Id.Id('362c1dbd-dc64-44bb-a3c4-652f38a642d7')],
properties: {
name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'),
description: Id.Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'),
},
},
Activity: {
typeIds: [Id.Id('8275c359-4662-40fb-9aec-27177b520cd2')],
properties: {
name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'),
},
relations: {
relatedSpaces: Id.Id('5b722cd3-61d6-494e-8887-1310566437ba'),
},
},
};`;

const mapping = buildMappingFile({
name: 'test',
description: 'test',
directory: 'test',
template: 'vite_react',
types: [
{
name: 'Space',
knowledgeGraphId: '362c1dbd-dc64-44bb-a3c4-652f38a642d7',
properties: [
{
name: 'Name',
knowledgeGraphId: 'a126ca53-0c8e-48d5-b888-82c734c38935',
dataType: 'Text',
},
{
name: 'Description',
knowledgeGraphId: '9b1f76ff-9711-404c-861e-59dc3fa7d037',
dataType: 'Text',
},
],
},
{
name: 'Activity',
knowledgeGraphId: '8275c359-4662-40fb-9aec-27177b520cd2',
properties: [
{
name: 'Name',
knowledgeGraphId: 'a126ca53-0c8e-48d5-b888-82c734c38935',
dataType: 'Text',
},
{
name: 'Description',
knowledgeGraphId: null,
dataType: 'Text',
},
{
name: 'Related spaces',
knowledgeGraphId: '5b722cd3-61d6-494e-8887-1310566437ba',
dataType: 'Relation(Related spaces)',
relationType: 'Related spaces',
},
],
},
],
});
expect(mapping).toBe(expectedMapping);
});
});
32 changes: 6 additions & 26 deletions pnpm-lock.yaml

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

Loading