private void HandleErrors(IGraphQLResponse response) { LastErrors = response.Errors; if (response.Errors == null || response.Errors.Count <= 0) { return; } Logger.Warn("Errors were found during the last GraphQL request."); if (ThrowOnAnyError) { throw new GraphQLClientException(response); } }
private async Task <IGraphQLResponse> SendXrayGraphQLQuery <T>(Func <string, string> postStringFunction) where T : GraphQLApiResponse, new() { try { GraphQLRequest.Query = XrayGraphQLQueries.GetQueryByType(new T(), postStringFunction); GraphQLResponse = await GraphQLClient.SendQueryAsync <T>(GraphQLRequest); return(GraphQLResponse); } catch (Exception) { return(GraphQLResponse); } }
public async void DeserializeFromUtf8StreamTest(string json, IGraphQLResponse expectedResponse) { var jsonBytes = Encoding.UTF8.GetBytes(json); await using var ms = new MemoryStream(jsonBytes); var response = await DeserializeToUnknownType(expectedResponse.Data?.GetType() ?? typeof(object), ms); //var response = await Serializer.DeserializeFromUtf8StreamAsync<object>(ms, CancellationToken.None); response.Data.Should().BeEquivalentTo(expectedResponse.Data, options => options.WithAutoConversion()); if (expectedResponse.Errors is null) { response.Errors.Should().BeNull(); } else { using (new AssertionScope()) { response.Errors.Should().NotBeNull(); response.Errors.Should().HaveSameCount(expectedResponse.Errors); for (int i = 0; i < expectedResponse.Errors.Length; i++) { response.Errors[i].Message.Should().BeEquivalentTo(expectedResponse.Errors[i].Message); response.Errors[i].Locations.Should().BeEquivalentTo(expectedResponse.Errors[i].Locations?.ToList()); response.Errors[i].Path.Should().BeEquivalentTo(expectedResponse.Errors[i].Path); response.Errors[i].Extensions.Should().BeEquivalentTo(expectedResponse.Errors[i].Extensions); } } } if (expectedResponse.Extensions == null) { response.Extensions.Should().BeNull(); } else { foreach (var element in expectedResponse.Extensions) { response.Extensions.Should().ContainKey(element.Key); response.Extensions[element.Key].Should().BeEquivalentTo(element.Value); } } }
public GraphQLClientException(IGraphQLResponse response) { GraphQLResponse = response; }