示例#1
0
        public async Task <IExecutionResult> ExecuteAsync(
            QueryRequest request,
            CancellationToken cancellationToken)
        {
            var remoteRquest = new ClientQueryRequest
            {
                Query         = request.Query,
                OperationName = request.OperationName,
                Variables     = request.VariableValues
            };

            var content = new StringContent(
                JsonConvert.SerializeObject(remoteRquest,
                                            new JsonSerializerSettings
            {
                ContractResolver =
                    new CamelCasePropertyNamesContractResolver()
            }),
                Encoding.UTF8,
                "application/json");

            HttpResponseMessage response = await _client.PostAsync("", content);

            string json = await response.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <ClientQueryResult>(json);

            OrderedDictionary data = result.Data == null
                ? null
                : result.Data.ToDictionary();

            return(new QueryResult(data));
        }
示例#2
0
        public async Task <IExecutionResult> ExecuteAsync(
            QueryRequest request,
            CancellationToken cancellationToken)
        {
            var remoteRquest = new ClientQueryRequest
            {
                Query         = request.Query,
                OperationName = request.OperationName,
                Variables     = request.VariableValues
            };
            var content = new StringContent(
                JsonConvert.SerializeObject(
                    remoteRquest,
                    new JsonSerializerSettings
            {
                ContractResolver =
                    new CamelCasePropertyNamesContractResolver()
            }),
                Encoding.UTF8,
                "application/json");
            HttpResponseMessage response = await _client
                                           .PostAsync(new Uri(""), content).ConfigureAwait(false);

            string json = await response.Content.ReadAsStringAsync()
                          .ConfigureAwait(false);

            ClientQueryResult result = JsonConvert
                                       .DeserializeObject <ClientQueryResult>(json);
            OrderedDictionary data = result.Data == null
                ? null
                : result.Data.ToDictionary();
            var queryResult = new QueryResult();

            if (data != null)
            {
                foreach (KeyValuePair <string, object> value in data)
                {
                    queryResult.Data[value.Key] = value.Value;
                }
            }

            return(queryResult);
        }