Graphql can't find entity by UUID

Having an entity UUID in a text field ‘Database Representation UUID’ of database ‘Utility/Database’, I try to get the database name of that entity. The purpose of the script is to maintain an up to date database name available as entity, to use in views and relationships. When the database name changes, the Utility/Database entity that represents it, will update that name using a script.

I came as far as trying to get the entity from the provide UUID, but for some reason the result is:

Console output:

Script execution error: Error: Entity with UUID fbdb1365-9267-4e87-a449-fc7e9a795e45 not found

The entity UUID above is actually present as entity of database ‘CCE Root/Page’, so the not found error is not because it does not exist.

Here is the script:

const fibery = context.getService('fibery');

async function main() {
    try {
        const entity = args.currentEntities[0];
        const entityWithUUID = await fibery.getEntityById('Utility/Database', entity.id, ['Database Representation Entity UUID']);
        const unknownEntityUUID = entityWithUUID['Database Representation Entity UUID'];

        // The space name
        const spaceName = 'CCE_Root';

        const query = `{getEntityById(id: "${unknownEntityUUID}") {id, name}}`;

        const result = await fibery.graphql(spaceName, query);

        if (result.data && result.data.getEntityById) {
            const unknownDatabaseName = result.data.getEntityById.name.split('/')[0];
            console.log(`Database name: ${unknownDatabaseName}`);
            return;  // Exit the function if the entity is found
        } else {
            throw new Error(`Entity with UUID ${unknownEntityUUID} not found.`);
        }

    } catch (error) {
        console.error(`Script execution error: ${error}`);
    }
}

await main().catch((error) => {
    console.error(`Main function error: ${error}`);
});

I don’t think that is possible, since entity UUID is only guaranteed to be unique within a particular Database - they are not globally unique. That’s why API calls like getEntityById require both the “Type” and “Id” to identify an entity.

2 Likes

There is no such method as getEntityById. Every database has it is own method to retrieve entities like findBugs(id:{is :"<UUID>"}){id}.

Please check Fibery GraphQL API

Thanks,
Oleg

1 Like