Exemplo n.º 1
0
        private void OperationSource_RecievePayload(object sender, PayloadEventArgs e)
        {
            if (_isStopped)
            {
                return;
            }

            // Get GraphQLResult
            var result = e.Payload.ToObject <GraphQLDataResult <JObject> >();

            // Add final result
            var finalResult = new GraphQLDataResult <T>()
            {
                Errors = result.Errors
            };

            // Deserilize data
            if (result.Data != null)
            {
                var data = deserialization.DeserializeResult <T>(result.Data, selectionSet);
                finalResult.Data = data;
            }

            // Send event
            if (result.ContainsErrors)
            {
                ErrorRecieved?.Invoke(this, new GraphQLDataReceivedEventArg <T>(finalResult));
            }
            else
            {
                DataRecieved?.Invoke(this, new GraphQLDataReceivedEventArg <T>(finalResult));
            }
        }
Exemplo n.º 2
0
        private async Task <GraphQLDataResult <T> > GetDataResult(CancellationToken cancellationToken)
        {
            // Generate query
            var query = _queryGenerator.GenerateQuery(OperationType, SelectionSet, _filter, _arguments);

            // Get result
            var result = await _executor.ExecuteQuery(
                query : query,
                url : _url,
                method : _httpMethod,
                authorizationToken : _authorizationToken,
                authorizationMethod : _authorizationMethod,
                cancellationToken : cancellationToken,
                headers : _headers).ConfigureAwait(false);

            // Deserilize
            var deserilizationResult = _deserilization.DeserializeResult <T>(result.Response, SelectionSet);

            if (deserilizationResult?.Errors?.Any() ?? false)
            {
                throw new GraphQLErrorException(query: query, errors: deserilizationResult.Errors);
            }

            // Set headers
            deserilizationResult.Headers = result.Headers;

            return(deserilizationResult);
        }
        private void OperationSource_RecievePayload(object sender, PayloadEventArgs e)
        {
            if (_isStopped)
            {
                return;
            }

            // Get GraphQLResult
            var result = e.Payload.ToObject <GraphQLDataResult <JObject> >();

            // Add final result
            var finalResult = new GraphQLDataResult <T>()
            {
                Errors = result.Errors
            };

            // Deserilize data
            if (result.Data != null)
            {
                try
                {
                    var data = deserialization.DeserializeResult <T>(result.Data, selectionSet);
                    finalResult.Data = data;
                }
                catch (Exception ex)
                {
                    Logger?.LogError(new EventId(2), ex, "Exception deserilizing message");

                    LogMessage(result);
                    // Ignored
                }
            }

            // Send event
            if (result.ContainsErrors)
            {
                ErrorRecieved?.Invoke(this, new GraphQLDataReceivedEventArg <T>(finalResult));
            }
            else
            {
                DataRecieved?.Invoke(this, new GraphQLDataReceivedEventArg <T>(finalResult));
            }
        }
        private async Task <GraphQLDataResult <T> > ExecuteQuery <T>(GraphQLOperationType operationType, IEnumerable <GraphQLField> selectionSet, GraphQLQueryArgument[] arguments, string url, HttpMethod httpMethod, IDictionary <string, string> headers, string authorizationMethod, string authorizationToken) where T : class
        {
            // Generate query
            var requestQuery = QueryGenerator.GenerateQuery(operationType, selectionSet, arguments.ToArray());

            // Get response
            GraphQLExecutorResponse response = await HttpExecutor.ExecuteQuery(requestQuery, url, httpMethod, headers : headers, authorizationToken : authorizationToken, authorizationMethod : authorizationMethod).ConfigureAwait(false);

            // Deserilize
            var result = Deserialization.DeserializeResult <T>(response.Response, selectionSet);

            if (result?.Errors?.Any() ?? false)
            {
                throw new GraphQLErrorException(query: requestQuery, errors: result.Errors);
            }

            // Set headers
            result.Headers = response.Headers;

            return(result);
        }