public IEnumerable <Dictionary <String, Object> > Resolve(ResolveFieldContext context)
        {
            var results = new List <Dictionary <String, Object> >();

            var       translator = new OeGraphqlAstToODataUri(_edmModel, context);
            ODataUri  odataUri   = translator.Translate(context.Document.OriginalQuery);
            IEdmModel refModel   = _edmModel.GetEdmModel(odataUri.Path);

            Db.OeDataAdapter dataAdapter = refModel.GetDataAdapter(refModel.EntityContainer);
            context.UserContext = dataAdapter.CreateDataContext();

            try
            {
                var queryContext = new Parsers.OeQueryContext(refModel, odataUri);
                IAsyncEnumerator <Object> asyncEnumerator = dataAdapter.Execute(context.UserContext, queryContext).GetEnumerator();
                using (var entityAsyncEnumerator = new OeGraphqlAsyncEnumerator(asyncEnumerator, queryContext.EntryFactory))
                {
                    while (entityAsyncEnumerator.MoveNext().GetAwaiter().GetResult())
                    {
                        results.Add(entityAsyncEnumerator.Current);
                    }
                }
            }
            finally
            {
                if (context.UserContext != null)
                {
                    dataAdapter.CloseDataContext(context.UserContext);
                }
            }

            return(results);
        }
        public Uri GetOdataUri(String query)
        {
            var context = new ResolveFieldContext()
            {
                Schema = Schema
            };
            var      translator = new OeGraphqlAstToODataUri(EdmModel, context);
            ODataUri odataUri   = translator.Translate(query);

            return(odataUri.BuildUri(ODataUrlKeyDelimiter.Parentheses));
        }
Example #3
0
        public async Task <IEnumerable <Dictionary <String, Object?> > > Resolve(IResolveFieldContext context)
        {
            var results = new List <Dictionary <String, Object?> >();

            var       translator = new OeGraphqlAstToODataUri(_edmModel, context);
            ODataUri  odataUri   = translator.Translate(context.Document.OriginalQuery);
            IEdmModel refModel   = _edmModel.GetEdmModel(odataUri.Path);

            Db.OeDataAdapter         dataAdapter           = refModel.GetDataAdapter(refModel.EntityContainer);
            Object                   dataContext           = dataAdapter.CreateDataContext();
            OeGraphqlAsyncEnumerator?entityAsyncEnumerator = null;

            try
            {
                var queryContext = new Parsers.OeQueryContext(refModel, odataUri);
                IAsyncEnumerator <Object> asyncEnumerator = dataAdapter.Execute(dataContext, queryContext).GetAsyncEnumerator();

                if (queryContext.EntryFactory == null)
                {
                    throw new InvalidOperationException("queryContext.EntryFactory must be not null");
                }

                entityAsyncEnumerator = new OeGraphqlAsyncEnumerator(asyncEnumerator, queryContext.EntryFactory, CancellationToken.None);
                while (await entityAsyncEnumerator.MoveNextAsync())
                {
                    if (entityAsyncEnumerator.Current != null)
                    {
                        results.Add(entityAsyncEnumerator.Current);
                    }
                }
            }
            finally
            {
                if (dataContext != null)
                {
                    dataAdapter.CloseDataContext(dataContext);
                }
                if (entityAsyncEnumerator != null)
                {
                    await entityAsyncEnumerator.DisposeAsync().ConfigureAwait(false);
                }
            }

            return(results);
        }