// uses helper decodeGlobalId to get the entity type and id from the globalId import { decodeGlobalId } from '@aztlan/react-relay' import { ObjectInterface } from '../interfaces/index.js' import * as entities from '../entities/index.js' import type { EntityType } from '../entities/types.js' type ResolveGlobalId = { id :string | undefined; Model:EntityType | ObjectInterface; } // taks the globalId and returns the entity type and id using switch const resolveGlobalId = (globalId: string): ResolveGlobalId => { if (!globalId) { return { id :undefined, // @ts-ignore Model:ObjectInterface, } } const { typeName, id, } = decodeGlobalId(globalId) const modelName = typeName.replace( /Node$/, '', ) const Model = entities[`${modelName}Entity`] console.log( 'RID', Model, modelName, entities, ) return { id, Model, } /* switch (type) { case 'Article': return new ArticleEntity({ id }) case 'Event': return new EventEntity({ id }) case 'Image': return new ImageEntity({ id }) case 'Collection': return new CollectionEntity({ id }) default: return ArticleEntity // throw new Error(`Unknown type: ${type}`) } */ } export default resolveGlobalId