private async Task <object> ResolveCkAttributesQuery(IResolveConnectionContext <object> arg) { Logger.Debug("GraphQL query handling of contruction kit attributes started"); var graphQlUserContext = (GraphQLUserContext)arg.UserContext; using var session = await graphQlUserContext.TenantContext.Repository.StartSessionAsync(); session.StartTransaction(); int?offset = arg.GetOffset(); DataQueryOperation dataQueryOperation = arg.GetDataQueryOperation(); arg.TryGetArgument(Statics.AttributeIdArg, out string key); arg.TryGetArgument(Statics.AttributeIdsArg, new List <string>(), out IEnumerable <string> keys); var keysList = keys.ToList(); if (!keysList.Any() && key != null) { keysList.Add(key); } var resultSet = await graphQlUserContext.TenantContext.Repository.GetCkAttributesAsync(session, keysList, dataQueryOperation, offset, arg.First); await session.CommitTransactionAsync(); Logger.Debug("GraphQL query handling returning data for contruction kit attributes"); return(ConnectionUtils.ToConnection(resultSet.Result.Select(CkAttributeDtoType.CreateCkAttributeDto), arg, resultSet.TotalCount > 0 ? offset.GetValueOrDefault(0) : 0, (int)resultSet.TotalCount)); }
private async Task <object> ResolveRtEntitiesQuery(IResolveConnectionContext <RtEntityDto> ctx) { var graphQlContext = (GraphQLUserContext)ctx.UserContext; using var session = await graphQlContext.TenantContext.Repository.StartSessionAsync(); session.StartTransaction(); var ckId = (string)ctx.FieldDefinition.Metadata[Statics.CkId]; var roleId = (string)ctx.FieldDefinition.Metadata[Statics.RoleId]; var graphDirections = (GraphDirections)ctx.FieldDefinition.Metadata[Statics.GraphDirection]; int?offset = ctx.GetOffset(); DataQueryOperation dataQueryOperation = ctx.GetDataQueryOperation(); if (ctx.Source.RtId != null) { var resultSet = await graphQlContext.TenantContext.Repository.GetRtAssociationTargetsAsync(session, ctx.Source.RtId.Value.ToObjectId(), roleId, ckId, graphDirections, dataQueryOperation, offset, ctx.First); return(ConnectionUtils.ToConnection(resultSet.Result.Select(RtEntityDtoType.CreateRtEntityDto), ctx, resultSet.TotalCount > 0 ? offset.GetValueOrDefault(0) : 0, (int)resultSet.TotalCount)); } await session.CommitTransactionAsync(); return(ConnectionUtils.ToConnection(new RtEntityDto[] { }, ctx, 0, 0)); }
private async Task <object> ResolveGenericRtEntitiesQuery(IResolveConnectionContext <object> arg) { Logger.Debug("GraphQL query handling for generic runtime entity started"); var graphQlUserContext = (GraphQLUserContext)arg.UserContext; var ckId = arg.GetArgument <string>(Statics.CkIdArg); using var session = await graphQlUserContext.TenantContext.Repository.StartSessionAsync(); session.StartTransaction(); int?offset = arg.GetOffset(); DataQueryOperation dataQueryOperation = arg.GetDataQueryOperation(); arg.TryGetArgument(Statics.RtIdArg, out OspObjectId? key); arg.TryGetArgument(Statics.RtIdsArg, new List <ObjectId>(), out IEnumerable <ObjectId> keys); var keysList = keys.ToList(); if (keysList.Any()) { var resultSetIds = await graphQlUserContext.TenantContext.Repository.GetRtEntitiesByIdAsync(session, ckId, keysList, dataQueryOperation, offset, arg.First); Logger.Debug("GraphQL query handling returning data by keys"); return(ConnectionUtils.ToConnection(resultSetIds.Result.Select(RtEntityDtoType.CreateRtEntityDto), arg, resultSetIds.TotalCount > 0 ? offset.GetValueOrDefault(0) : 0, (int)resultSetIds.TotalCount)); } if (key.HasValue) { var result = await graphQlUserContext.TenantContext.Repository.GetRtEntityAsync(session, new RtEntityId(ckId, key.Value)); var resultList = new List <RtEntityDto>(); if (result != null) { resultList.Add(RtEntityDtoType.CreateRtEntityDto(result)); } Logger.Debug("GraphQL query handling returning data by key"); return(ConnectionUtils.ToConnection(resultList, arg)); } var resultSet = await graphQlUserContext.TenantContext.Repository.GetRtEntitiesByTypeAsync(session, ckId, dataQueryOperation, offset, arg.First); await session.CommitTransactionAsync(); Logger.Debug("GraphQL query handling returning data"); return(ConnectionUtils.ToConnection(resultSet.Result.Select(RtEntityDtoType.CreateRtEntityDto), arg, resultSet.TotalCount > 0 ? offset.GetValueOrDefault(0) : 0, (int)resultSet.TotalCount)); }