import { Arg, Ctx, Query, Resolver } from 'type-graphql' import { getRepository } from '@things-factory/shell' import { TwinReferenceReconciliation } from './twin-reference-reconciliation.js' @Resolver() export class TwinReferenceReconciliationQuery { @Query(returns => [TwinReferenceReconciliation], { description: 'All latest durable sequence reconciliations for one Twin. An empty list means no numbered source range has been read yet, not that every source is aligned.' }) async twinReferenceReconciliations( @Arg('instanceId') instanceId: string, @Ctx() context: ResolverContext ): Promise { return getRepository(TwinReferenceReconciliation).find({ where: { domain: { id: context.state.domain.id }, instanceId }, order: { scope: 'ASC' } }) } @Query(returns => TwinReferenceReconciliation, { nullable: true, description: 'Latest durable source-range versus Twin-cursor reconciliation for one numbered scope. Null means no backfill has yet obtained a source range; it is not an aligned result.' }) async twinReferenceReconciliation( @Arg('instanceId') instanceId: string, @Arg('scope') scope: string, @Ctx() context: ResolverContext ): Promise { return getRepository(TwinReferenceReconciliation).findOne({ where: { domain: { id: context.state.domain.id }, instanceId, scope } }) } }