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> 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));
        }
        private object ResolveAttributes(IResolveConnectionContext <CkEntityDto> ctx)
        {
            var graphQlContext = (GraphQLUserContext)ctx.UserContext;

            ctx.TryGetArgument(Statics.AttributeNamesFilterArg, out IEnumerable <string> filterAttributeNames);

            var entityCacheItem = graphQlContext.TenantContext.CkCache.GetEntityCacheItem(ctx.Source.CkId);

            IEnumerable <AttributeCacheItem> resultList;

            if (filterAttributeNames == null)
            {
                resultList = entityCacheItem.Attributes.Values;
            }
            else
            {
                resultList =
                    entityCacheItem.Attributes.Values.Where(a =>
                                                            filterAttributeNames.Contains(StringExtensions.ToCamelCase(a.AttributeName)));
            }

            return(ConnectionUtils.ToConnection(resultList.Select(CreateCkEntityAttributeDto), ctx));
        }