diff --git a/root.props b/root.props index e2fc2d0c..ee96815f 100644 --- a/root.props +++ b/root.props @@ -6,7 +6,7 @@ A GraphQL Client for .NET Standard True True - latest + 8.0 en-US CS0618;CS1591;CS1701 https://raw.githubusercontent.com/graphql-dotnet/graphql-client/master/assets/logo.64x64.png diff --git a/src/GraphQL.Client/GraphQL.Client.csproj b/src/GraphQL.Client/GraphQL.Client.csproj index 99a24460..572356d7 100644 --- a/src/GraphQL.Client/GraphQL.Client.csproj +++ b/src/GraphQL.Client/GraphQL.Client.csproj @@ -1,11 +1,11 @@ - + A GraphQL Client - netstandard1.3;netstandard2.0 + netstandard2.0 diff --git a/src/GraphQL.Client/Http/GraphQLHttpClient.cs b/src/GraphQL.Client/Http/GraphQLHttpClient.cs index 58da72ee..fe7bd7e7 100644 --- a/src/GraphQL.Client/Http/GraphQLHttpClient.cs +++ b/src/GraphQL.Client/Http/GraphQLHttpClient.cs @@ -101,20 +101,20 @@ internal GraphQLHttpClient(GraphQLHttpClientOptions options, HttpClient httpClie } public Task SendQueryAsync(string query, CancellationToken cancellationToken = default) => - this.SendQueryAsync(new GraphQLRequest { Query = query }, cancellationToken); + this.SendQueryAsync(new GraphQLRequest(query), cancellationToken); public Task SendQueryAsync(GraphQLRequest request, CancellationToken cancellationToken = default) => this.graphQLHttpHandler.PostAsync(request, cancellationToken); public Task SendMutationAsync(string query, CancellationToken cancellationToken = default) => - this.SendMutationAsync(new GraphQLRequest { Query = query }, cancellationToken); + this.SendMutationAsync(new GraphQLRequest(query), cancellationToken); public Task SendMutationAsync(GraphQLRequest request, CancellationToken cancellationToken = default) => this.graphQLHttpHandler.PostAsync(request, cancellationToken); [Obsolete("EXPERIMENTAL API")] public Task SendSubscribeAsync(string query, CancellationToken cancellationToken = default) => - this.SendSubscribeAsync(new GraphQLRequest { Query = query }, cancellationToken); + this.SendSubscribeAsync(new GraphQLRequest(query), cancellationToken); [Obsolete("EXPERIMENTAL API")] public Task SendSubscribeAsync(GraphQLRequest request, CancellationToken cancellationToken = default) { diff --git a/src/GraphQL.Client/Obsolete.GraphQLClient.Extensions.cs b/src/GraphQL.Client/Obsolete.GraphQLClient.Extensions.cs index a7b6dbfc..057e3c8a 100644 --- a/src/GraphQL.Client/Obsolete.GraphQLClient.Extensions.cs +++ b/src/GraphQL.Client/Obsolete.GraphQLClient.Extensions.cs @@ -99,8 +99,8 @@ fragment TypeRef on __Type { } }"; - private static readonly GraphQLRequest IntrospectionGraphQLRequest = new GraphQLRequest { - Query = IntrospectionQuery.Replace("\t", "").Replace("\n", "").Replace("\r", ""), + private static readonly GraphQLRequest IntrospectionGraphQLRequest = new GraphQLRequest( + IntrospectionQuery.Replace("\t", "").Replace("\n", "").Replace("\r", "")){ Variables = null }; diff --git a/src/GraphQL.Client/Obsolete.GraphQLClient.cs b/src/GraphQL.Client/Obsolete.GraphQLClient.cs index 73f81450..922927bf 100644 --- a/src/GraphQL.Client/Obsolete.GraphQLClient.cs +++ b/src/GraphQL.Client/Obsolete.GraphQLClient.cs @@ -53,7 +53,7 @@ public GraphQLClient(GraphQLClientOptions options) : base(options) { } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// The Response public Task GetQueryAsync(string query, CancellationToken cancellationToken = default) => - this.GetAsync(new GraphQLRequest { Query = query }, cancellationToken); + this.GetAsync(new GraphQLRequest(query), cancellationToken); /// /// Send a via GET @@ -71,7 +71,7 @@ public Task GetAsync(GraphQLRequest request, CancellationToken /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// The Response public Task PostQueryAsync(string query, CancellationToken cancellationToken = default) => - this.PostAsync(new GraphQLRequest { Query = query }, cancellationToken); + this.PostAsync(new GraphQLRequest(query), cancellationToken); /// /// Send a via POST diff --git a/src/GraphQL.Common/GraphQL.Common.csproj b/src/GraphQL.Common/GraphQL.Common.csproj index ed75f9dd..116ff1b9 100644 --- a/src/GraphQL.Common/GraphQL.Common.csproj +++ b/src/GraphQL.Common/GraphQL.Common.csproj @@ -1,4 +1,4 @@ - + @@ -8,7 +8,7 @@ - netstandard1.0;netstandard2.0 + netstandard2.0 diff --git a/src/GraphQL.Common/Request/GraphQLRequest.cs b/src/GraphQL.Common/Request/GraphQLRequest.cs index 212a3642..42f1231d 100644 --- a/src/GraphQL.Common/Request/GraphQLRequest.cs +++ b/src/GraphQL.Common/Request/GraphQLRequest.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; @@ -7,7 +8,7 @@ namespace GraphQL.Common.Request { /// Represents a Query that can be fetched to a GraphQL Server. /// For more information /// - public class GraphQLRequest : IEquatable { + public class GraphQLRequest : IEquatable { /// /// The Query @@ -17,50 +18,40 @@ public class GraphQLRequest : IEquatable { /// /// If the provided contains multiple named operations, this specifies which operation should be executed. /// - public string OperationName { get; set; } + public string? OperationName { get; set; } /// /// The Variables /// - public dynamic Variables { get; set; } + public dynamic? Variables { get; set; } + + /// + /// Initialize a new GraphQLRequest + /// + /// The Query + public GraphQLRequest(string query){ + this.Query = query; + } /// - public override bool Equals(object obj) => this.Equals(obj as GraphQLRequest); + public override bool Equals(object? obj) => this.Equals(obj as GraphQLRequest); /// - public bool Equals(GraphQLRequest other) { + public bool Equals(GraphQLRequest? other) { if (other == null) { return false; } - if (ReferenceEquals(this, other)) { - return true; - } - if (!Equals(this.Query, other.Query)) { - return false; - } - if (!Equals(this.OperationName, other.OperationName)) { - return false; - } - if (!Equals(this.Variables, other.Variables)) { - return false; - } - return true; + return EqualityComparer.Default.Equals(this, other); } /// - public override int GetHashCode() { - var hashCode = -689803966; - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(this.Query); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(this.OperationName); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(this.Variables); - return hashCode; - } + public override int GetHashCode() => EqualityComparer.Default.GetHashCode(this); /// - public static bool operator ==(GraphQLRequest request1, GraphQLRequest request2) => EqualityComparer.Default.Equals(request1, request2); + public static bool operator ==(GraphQLRequest? request1, GraphQLRequest? request2) => EqualityComparer.Default.Equals(request1, request2); /// - public static bool operator !=(GraphQLRequest request1, GraphQLRequest request2) => !(request1 == request2); + public static bool operator !=(GraphQLRequest? request1, GraphQLRequest? request2) => !(request1 == request2); } diff --git a/tests/GraphQL.Client.Tests/GraphQLClientGetTests.cs b/tests/GraphQL.Client.Tests/GraphQLClientGetTests.cs index faad38e8..2cdc0dfa 100644 --- a/tests/GraphQL.Client.Tests/GraphQLClientGetTests.cs +++ b/tests/GraphQL.Client.Tests/GraphQLClientGetTests.cs @@ -8,14 +8,12 @@ public class GraphQLClientGetTests : BaseGraphQLClientTest { [Fact] public async void QueryGetAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" { person(personID: ""1"") { name } - }" - }; + }"); var response = await this.GraphQLClient.GetAsync(graphQLRequest).ConfigureAwait(false); Assert.Equal("Luke Skywalker", response.Data.person.name.Value); @@ -24,8 +22,7 @@ public async void QueryGetAsyncFact() { [Fact] public async void OperationNameGetAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" query Person{ person(personID: ""1"") { name @@ -36,7 +33,7 @@ query Planet { planet(planetID: ""1"") { name } - }", + }") { OperationName = "Person" }; var response = await this.GraphQLClient.GetAsync(graphQLRequest).ConfigureAwait(false); @@ -47,13 +44,12 @@ query Planet { [Fact] public async void VariablesGetAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest (@" query Person($personId: ID!){ person(personID: $personId) { name } - }", + }") { Variables = new { personId = "1" } @@ -66,8 +62,7 @@ query Person($personId: ID!){ [Fact] public async void OperationNameVariableGetAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" query Person($personId: ID!){ person(personID: $personId) { name @@ -78,7 +73,7 @@ query Planet { planet(planetID: ""1"") { name } - }", + }"){ OperationName = "Person", Variables = new { personId = "1" diff --git a/tests/GraphQL.Client.Tests/GraphQLClientPostTests.cs b/tests/GraphQL.Client.Tests/GraphQLClientPostTests.cs index ba56c9a1..aacc1587 100644 --- a/tests/GraphQL.Client.Tests/GraphQLClientPostTests.cs +++ b/tests/GraphQL.Client.Tests/GraphQLClientPostTests.cs @@ -9,14 +9,13 @@ public class GraphQLClientPostTests : BaseGraphQLClientTest { [Fact] public async void QueryPostAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" { person(personID: ""1"") { name } }" - }; + ); var response = await this.GraphQLClient.PostAsync(graphQLRequest).ConfigureAwait(false); Assert.Equal("Luke Skywalker", response.Data.person.name.Value); @@ -24,17 +23,14 @@ public async void QueryPostAsyncFact() { } [Fact] - public async void QueryPostAsyncWithoutUtf8EncodingFact() - { - var graphQLRequest = new GraphQLRequest - { - Query = @" + public async void QueryPostAsyncWithoutUtf8EncodingFact(){ + var graphQLRequest = new GraphQLRequest(@" { person(personID: ""1"") { name } }" - }; + ); this.GraphQLClient.Options.MediaType = MediaTypeHeaderValue.Parse("application/json"); var response = await this.GraphQLClient.PostAsync(graphQLRequest).ConfigureAwait(false); @@ -44,8 +40,7 @@ public async void QueryPostAsyncWithoutUtf8EncodingFact() [Fact] public async void OperationNamePostAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" query Person{ person(personID: ""1"") { name @@ -56,7 +51,7 @@ query Planet { planet(planetID: ""1"") { name } - }", + }") { OperationName = "Person" }; var response = await this.GraphQLClient.PostAsync(graphQLRequest).ConfigureAwait(false); @@ -67,13 +62,12 @@ query Planet { [Fact] public async void VariablesPostAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" query Person($personId: ID!){ person(personID: $personId) { name } - }", + }") { Variables = new { personId = "1" } @@ -86,8 +80,7 @@ query Person($personId: ID!){ [Fact] public async void OperationNameVariablePostAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" query Person($personId: ID!){ person(personID: $personId) { name @@ -98,7 +91,7 @@ query Planet { planet(planetID: ""1"") { name } - }", + }") { OperationName = "Person", Variables = new { personId = "1" diff --git a/tests/GraphQL.Client.Tests/Http/GraphQLHttpClientSendQueryAsyncTest.cs b/tests/GraphQL.Client.Tests/Http/GraphQLHttpClientSendQueryAsyncTest.cs index 82062542..2d21100e 100644 --- a/tests/GraphQL.Client.Tests/Http/GraphQLHttpClientSendQueryAsyncTest.cs +++ b/tests/GraphQL.Client.Tests/Http/GraphQLHttpClientSendQueryAsyncTest.cs @@ -1,42 +1,36 @@ -using GraphQL.Client.Http; -using GraphQL.Common.Request; using System; -using System.Collections.Generic; using System.Net.Http; -using System.Text; using System.Threading; using System.Threading.Tasks; +using GraphQL.Client.Http; +using GraphQL.Common.Request; using Xunit; namespace GraphQL.Client.Tests.Http { - public class GraphQLHttpClientSendQueryAsyncTest - { + + public class GraphQLHttpClientSendQueryAsyncTest{ // Relates to an issue with the 1.x versions. // See: https://github.com/graphql-dotnet/graphql-client/issues/53 [Fact] - public async void SendQueryAsyncShouldPreserveUriParametersFact() - { + public async void SendQueryAsyncShouldPreserveUriParametersFact(){ var endpoint = new Uri("http://localhost/api/graphql?code=my-secret-api-key"); var handlerStub = new HttpHandlerStub(); - GraphQLHttpClientOptions options = new GraphQLHttpClientOptions() - { + var options = new GraphQLHttpClientOptions(){ EndPoint = endpoint, HttpMessageHandler = handlerStub }; - GraphQLHttpClient systemUnderTest = new GraphQLHttpClient(options); + var systemUnderTest = new GraphQLHttpClient(options); - var response = await systemUnderTest.SendQueryAsync(new GraphQLRequest - { - Query = @" + var response = await systemUnderTest.SendQueryAsync(new GraphQLRequest(@" { person(personID: ""1"") { name } }" - }); + )); var actualRequestUri = handlerStub.LastRequest.RequestUri; var queryParams = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(actualRequestUri.Query); @@ -45,20 +39,21 @@ public async void SendQueryAsyncShouldPreserveUriParametersFact() } - private class HttpHandlerStub : HttpMessageHandler - { + private class HttpHandlerStub : HttpMessageHandler{ + public HttpRequestMessage LastRequest { get; private set; } public CancellationToken LastCancellationToken { get; private set; } - protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) - { - LastRequest = request; - LastCancellationToken = cancellationToken; - var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - response.Content = new StringContent("{}"); + protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken){ + this.LastRequest = request; + this.LastCancellationToken = cancellationToken; + var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK){ + Content = new StringContent("{}") + }; return Task.FromResult(response); } + } } diff --git a/tests/GraphQL.Client.Tests/Http/HttpClientExtensionsTest.cs b/tests/GraphQL.Client.Tests/Http/HttpClientExtensionsTest.cs index 1738f0a2..607c7e28 100644 --- a/tests/GraphQL.Client.Tests/Http/HttpClientExtensionsTest.cs +++ b/tests/GraphQL.Client.Tests/Http/HttpClientExtensionsTest.cs @@ -13,14 +13,13 @@ public class HttpClientExtensionsTest : BaseGraphQLClientTest { [Fact] public async void QueryGetAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" { person(personID: ""1"") { name } }" - }; + ); var response = await this.GraphQLHttpClient.SendQueryAsync(graphQLRequest).ConfigureAwait(false); Assert.Equal("Luke Skywalker", response.Data.person.name.Value); @@ -29,8 +28,7 @@ public async void QueryGetAsyncFact() { [Fact] public async void OperationNameGetAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" query Person{ person(personID: ""1"") { name @@ -41,7 +39,7 @@ query Planet { planet(planetID: ""1"") { name } - }", + }"){ OperationName = "Person" }; var response = await this.GraphQLHttpClient.SendQueryAsync(graphQLRequest).ConfigureAwait(false); @@ -52,13 +50,12 @@ query Planet { [Fact] public async void VariablesGetAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" query Person($personId: ID!){ person(personID: $personId) { name } - }", + }") { Variables = new { personId = "1" } @@ -71,8 +68,7 @@ query Person($personId: ID!){ [Fact] public async void OperationNameVariableGetAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" query Person($personId: ID!){ person(personID: $personId) { name @@ -83,7 +79,7 @@ query Planet { planet(planetID: ""1"") { name } - }", + }") { OperationName = "Person", Variables = new { personId = "1" diff --git a/tests/GraphQL.Client.Tests/IGraphQLClientTest.cs b/tests/GraphQL.Client.Tests/IGraphQLClientTest.cs index 7b5b6368..7c384d55 100644 --- a/tests/GraphQL.Client.Tests/IGraphQLClientTest.cs +++ b/tests/GraphQL.Client.Tests/IGraphQLClientTest.cs @@ -8,14 +8,13 @@ public class IGraphQLClientTest : BaseGraphQLClientTest { [Fact] public async void QueryGetAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" { person(personID: ""1"") { name } }" - }; + ); var response = await this.GraphQLClientSwapi.SendQueryAsync(graphQLRequest).ConfigureAwait(false); Assert.Equal("Luke Skywalker", response.Data.person.name.Value); @@ -24,8 +23,7 @@ public async void QueryGetAsyncFact() { [Fact] public async void OperationNameGetAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" query Person{ person(personID: ""1"") { name @@ -36,7 +34,7 @@ query Planet { planet(planetID: ""1"") { name } - }", + }") { OperationName = "Person" }; var response = await this.GraphQLClientSwapi.SendQueryAsync(graphQLRequest).ConfigureAwait(false); @@ -47,13 +45,12 @@ query Planet { [Fact] public async void VariablesGetAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" query Person($personId: ID!){ person(personID: $personId) { name } - }", + }") { Variables = new { personId = "1" } @@ -66,8 +63,7 @@ query Person($personId: ID!){ [Fact] public async void OperationNameVariableGetAsyncFact() { - var graphQLRequest = new GraphQLRequest { - Query = @" + var graphQLRequest = new GraphQLRequest(@" query Person($personId: ID!){ person(personID: $personId) { name @@ -78,7 +74,7 @@ query Planet { planet(planetID: ""1"") { name } - }", + }") { OperationName = "Person", Variables = new { personId = "1" diff --git a/tests/GraphQL.Common.Tests/AssertGraphQL.cs b/tests/GraphQL.Common.Tests/AssertGraphQL.cs index a81f38ad..4115fc9f 100644 --- a/tests/GraphQL.Common.Tests/AssertGraphQL.cs +++ b/tests/GraphQL.Common.Tests/AssertGraphQL.cs @@ -6,8 +6,6 @@ namespace GraphQL.Common.Tests { public static class AssertGraphQL { - public static void CorrectGraphQLRequest(GraphQLRequest graphQLRequest) => Assert.NotNull(graphQLRequest.Query); - public static void CorrectGraphQLResponse(GraphQLResponse graphQLResponse) { Assert.NotNull(graphQLResponse.Data); Assert.Null(graphQLResponse.Errors); diff --git a/tests/GraphQL.Common.Tests/Request/GraphQLRequestConsts.cs b/tests/GraphQL.Common.Tests/Request/GraphQLRequestConsts.cs index 9d3fca63..520ca4b6 100644 --- a/tests/GraphQL.Common.Tests/Request/GraphQLRequestConsts.cs +++ b/tests/GraphQL.Common.Tests/Request/GraphQLRequestConsts.cs @@ -7,130 +7,122 @@ public static class GraphQLRequestConsts { /// /// /// - public static GraphQLRequest FieldsRequest1 { get; } = new GraphQLRequest { - Query = @" - { - hero { - name - } - }", + public static GraphQLRequest FieldsRequest1 { get; } = new GraphQLRequest(@" + { + hero { + name + } + }") { Variables = null }; /// /// /// - public static GraphQLRequest FieldsRequest2 { get; } = new GraphQLRequest { - Query = @" - { - hero { + public static GraphQLRequest FieldsRequest2 { get; } = new GraphQLRequest(@" + { + hero { + name + # Queries can have comments! + friends { name - # Queries can have comments! - friends { - name - } } - }", + } + }") { Variables = null }; /// /// /// - public static GraphQLRequest ArgumentsRequest1 { get; } = new GraphQLRequest { - Query = @" - { - human(id: ""1000"") { - name - height - } - }", + public static GraphQLRequest ArgumentsRequest1 { get; } = new GraphQLRequest(@" + { + human(id: ""1000"") { + name + height + } + }") { Variables = null }; /// /// /// - public static GraphQLRequest ArgumentsRequest2 { get; } = new GraphQLRequest { - Query = @" - { - human(id: ""1000"") { - name - height(unit: FOOT) - } - }", + public static GraphQLRequest ArgumentsRequest2 { get; } = new GraphQLRequest(@" + { + human(id: ""1000"") { + name + height(unit: FOOT) + } + }") { Variables = null }; /// /// /// - public static GraphQLRequest AliasesRequest { get; } = new GraphQLRequest { - Query = @" - { - empireHero: hero(episode: EMPIRE) { - name - } - jediHero: hero(episode: JEDI) { - name - } - }", + public static GraphQLRequest AliasesRequest { get; } = new GraphQLRequest(@" + { + empireHero: hero(episode: EMPIRE) { + name + } + jediHero: hero(episode: JEDI) { + name + } + }") { Variables = null }; /// /// /// - public static GraphQLRequest FragmentsRequest { get; } = new GraphQLRequest { - Query = @" - { - leftComparison: hero(episode: EMPIRE) { - ...comparisonFields - } - rightComparison: hero(episode: JEDI) { - ...comparisonFields - } + public static GraphQLRequest FragmentsRequest { get; } = new GraphQLRequest(@" + { + leftComparison: hero(episode: EMPIRE) { + ...comparisonFields + } + rightComparison: hero(episode: JEDI) { + ...comparisonFields } + } - fragment comparisonFields on Character { + fragment comparisonFields on Character { + name + appearsIn + friends { name - appearsIn - friends { - name - } - }", + } + }") { Variables = null }; /// /// /// - public static GraphQLRequest OperationNameRequest { get; } = new GraphQLRequest { - Query = @" - query HeroNameAndFriends { - hero { + public static GraphQLRequest OperationNameRequest { get; } = new GraphQLRequest(@" + query HeroNameAndFriends { + hero { + name + friends { name - friends { - name - } } - }", + } + }") { Variables = null }; /// /// /// - public static GraphQLRequest VariablesRequest { get; } = new GraphQLRequest { - Query = @" - query HeroNameAndFriends($episode: Episode) { - hero(episode: $episode) { + public static GraphQLRequest VariablesRequest { get; } = new GraphQLRequest(@" + query HeroNameAndFriends($episode: Episode) { + hero(episode: $episode) { + name + friends { name - friends { - name - } } - }", + } + }") { Variables = new { episode = "JEDI" } @@ -139,16 +131,15 @@ query HeroNameAndFriends($episode: Episode) { /// /// /// - public static GraphQLRequest DirectivesRequest { get; } = new GraphQLRequest { - Query = @" - query Hero($episode: Episode, $withFriends: Boolean!) { - hero(episode: $episode) { + public static GraphQLRequest DirectivesRequest { get; } = new GraphQLRequest(@" + query Hero($episode: Episode, $withFriends: Boolean!) { + hero(episode: $episode) { + name + friends @include(if: $withFriends) { name - friends @include(if: $withFriends) { - name - } } - }", + } + }") { Variables = new { episode = "JEDI", withFriends = false @@ -158,14 +149,13 @@ friends @include(if: $withFriends) { /// /// /// - public static GraphQLRequest MutationsRequest { get; } = new GraphQLRequest { - Query = @" - mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) { - createReview(episode: $ep, review: $review) { - stars - commentary - } - }", + public static GraphQLRequest MutationsRequest { get; } = new GraphQLRequest(@" + mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) { + createReview(episode: $ep, review: $review) { + stars + commentary + } + }") { Variables = new { ep = "JEDI", review = new { @@ -178,19 +168,18 @@ mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) { /// /// /// - public static GraphQLRequest InlineFragmentsRequest { get; } = new GraphQLRequest { - Query = @" - query HeroForEpisode($ep: Episode!) { - hero(episode: $ep) { - name - ... on Droid { - primaryFunction - } - ... on Human { - height - } + public static GraphQLRequest InlineFragmentsRequest { get; } = new GraphQLRequest(@" + query HeroForEpisode($ep: Episode!) { + hero(episode: $ep) { + name + ... on Droid { + primaryFunction } - }", + ... on Human { + height + } + } + }") { Variables = new { ep = "JEDI" } @@ -199,22 +188,21 @@ ... on Human { /// /// /// - public static GraphQLRequest MetaFieldsRequest { get; } = new GraphQLRequest { - Query = @" - { - search(text: ""an"") { - __typename - ...on Human { - name - } - ... on Droid { - name - } - ... on Starship { - name - } + public static GraphQLRequest MetaFieldsRequest { get; } = new GraphQLRequest(@" + { + search(text: ""an"") { + __typename + ...on Human { + name + } + ... on Droid { + name } - }", + ... on Starship { + name + } + } + }") { Variables = null }; diff --git a/tests/GraphQL.Common.Tests/Request/GraphQLRequestTests.cs b/tests/GraphQL.Common.Tests/Request/GraphQLRequestTests.cs index 2512fe3b..6eb0febd 100644 --- a/tests/GraphQL.Common.Tests/Request/GraphQLRequestTests.cs +++ b/tests/GraphQL.Common.Tests/Request/GraphQLRequestTests.cs @@ -7,49 +7,41 @@ public class GraphQLRequestTests { [Fact] public void FieldsRequest1Fact() { var graphQLRequest = GraphQLRequestConsts.FieldsRequest1; - AssertGraphQL.CorrectGraphQLRequest(graphQLRequest); } [Fact] public void FieldsRequest2Fact() { var graphQLRequest = GraphQLRequestConsts.FieldsRequest2; - AssertGraphQL.CorrectGraphQLRequest(graphQLRequest); } [Fact] public void ArgumentsRequest1Fact() { var graphQLRequest = GraphQLRequestConsts.ArgumentsRequest1; - AssertGraphQL.CorrectGraphQLRequest(graphQLRequest); } [Fact] public void ArgumentsRequest2Fact() { var graphQLRequest = GraphQLRequestConsts.ArgumentsRequest2; - AssertGraphQL.CorrectGraphQLRequest(graphQLRequest); } [Fact] public void AliasesRequestFact() { var graphQLRequest = GraphQLRequestConsts.AliasesRequest; - AssertGraphQL.CorrectGraphQLRequest(graphQLRequest); } [Fact] public void FragmentsRequestFact() { var graphQLRequest = GraphQLRequestConsts.FragmentsRequest; - AssertGraphQL.CorrectGraphQLRequest(graphQLRequest); } [Fact] public void OperationNameRequestFact() { var graphQLRequest = GraphQLRequestConsts.OperationNameRequest; - AssertGraphQL.CorrectGraphQLRequest(graphQLRequest); } [Fact] public void VariablesRequestFact() { var graphQLRequest = GraphQLRequestConsts.VariablesRequest; - AssertGraphQL.CorrectGraphQLRequest(graphQLRequest); Assert.NotNull(graphQLRequest.Variables); Assert.Equal("JEDI", graphQLRequest.Variables.episode); } @@ -57,7 +49,6 @@ public void VariablesRequestFact() { [Fact] public void DirectivesRequestFact() { var graphQLRequest = GraphQLRequestConsts.DirectivesRequest; - AssertGraphQL.CorrectGraphQLRequest(graphQLRequest); Assert.NotNull(graphQLRequest.Variables); Assert.Equal("JEDI", graphQLRequest.Variables.episode); Assert.Equal(false, graphQLRequest.Variables.withFriends); @@ -66,7 +57,6 @@ public void DirectivesRequestFact() { [Fact] public void MutationsRequestFact() { var graphQLRequest = GraphQLRequestConsts.MutationsRequest; - AssertGraphQL.CorrectGraphQLRequest(graphQLRequest); Assert.NotNull(graphQLRequest.Variables); Assert.Equal("JEDI", graphQLRequest.Variables.ep); Assert.Equal(5, graphQLRequest.Variables.review.stars); @@ -76,7 +66,6 @@ public void MutationsRequestFact() { [Fact] public void InlineFragmentsRequestFact() { var graphQLRequest = GraphQLRequestConsts.InlineFragmentsRequest; - AssertGraphQL.CorrectGraphQLRequest(graphQLRequest); Assert.NotNull(graphQLRequest.Variables); Assert.Equal("JEDI", graphQLRequest.Variables.ep); } @@ -84,7 +73,6 @@ public void InlineFragmentsRequestFact() { [Fact] public void MetaFieldsRequestFact() { var graphQLRequest = GraphQLRequestConsts.MetaFieldsRequest; - AssertGraphQL.CorrectGraphQLRequest(graphQLRequest); } }