Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion root.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Description>A GraphQL Client for .NET Standard</Description>
<GenerateAssemblyInfo>True</GenerateAssemblyInfo>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>
<LangVersion>8.0</LangVersion>
<NeutralLanguage>en-US</NeutralLanguage>
<NoWarn>CS0618;CS1591;CS1701</NoWarn>
<PackageIconUrl>https://raw.githubusercontent.com/graphql-dotnet/graphql-client/master/assets/logo.64x64.png</PackageIconUrl>
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL.Client/GraphQL.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../src.props" />

<PropertyGroup>
<Description>A GraphQL Client</Description>
<TargetFrameworks>netstandard1.3;netstandard2.0</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQL.Client/Http/GraphQLHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,20 @@ internal GraphQLHttpClient(GraphQLHttpClientOptions options, HttpClient httpClie
}

public Task<GraphQLResponse> SendQueryAsync(string query, CancellationToken cancellationToken = default) =>
this.SendQueryAsync(new GraphQLRequest { Query = query }, cancellationToken);
this.SendQueryAsync(new GraphQLRequest(query), cancellationToken);

public Task<GraphQLResponse> SendQueryAsync(GraphQLRequest request, CancellationToken cancellationToken = default) =>
this.graphQLHttpHandler.PostAsync(request, cancellationToken);

public Task<GraphQLResponse> SendMutationAsync(string query, CancellationToken cancellationToken = default) =>
this.SendMutationAsync(new GraphQLRequest { Query = query }, cancellationToken);
this.SendMutationAsync(new GraphQLRequest(query), cancellationToken);

public Task<GraphQLResponse> SendMutationAsync(GraphQLRequest request, CancellationToken cancellationToken = default) =>
this.graphQLHttpHandler.PostAsync(request, cancellationToken);

[Obsolete("EXPERIMENTAL API")]
public Task<IGraphQLSubscriptionResult> SendSubscribeAsync(string query, CancellationToken cancellationToken = default) =>
this.SendSubscribeAsync(new GraphQLRequest { Query = query }, cancellationToken);
this.SendSubscribeAsync(new GraphQLRequest(query), cancellationToken);

[Obsolete("EXPERIMENTAL API")]
public Task<IGraphQLSubscriptionResult> SendSubscribeAsync(GraphQLRequest request, CancellationToken cancellationToken = default) {
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL.Client/Obsolete.GraphQLClient.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL.Client/Obsolete.GraphQLClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public GraphQLClient(GraphQLClientOptions options) : base(options) { }
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>The Response</returns>
public Task<GraphQLResponse> GetQueryAsync(string query, CancellationToken cancellationToken = default) =>
this.GetAsync(new GraphQLRequest { Query = query }, cancellationToken);
this.GetAsync(new GraphQLRequest(query), cancellationToken);

/// <summary>
/// Send a <see cref="GraphQLRequest"/> via GET
Expand All @@ -71,7 +71,7 @@ public Task<GraphQLResponse> GetAsync(GraphQLRequest request, CancellationToken
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>The Response</returns>
public Task<GraphQLResponse> PostQueryAsync(string query, CancellationToken cancellationToken = default) =>
this.PostAsync(new GraphQLRequest { Query = query }, cancellationToken);
this.PostAsync(new GraphQLRequest(query), cancellationToken);

/// <summary>
/// Send a <see cref="GraphQLRequest"/> via POST
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL.Common/GraphQL.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../src.props" />
Expand All @@ -8,7 +8,7 @@
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>netstandard1.0;netstandard2.0</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
45 changes: 18 additions & 27 deletions src/GraphQL.Common/Request/GraphQLRequest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections.Generic;

Expand All @@ -7,7 +8,7 @@ namespace GraphQL.Common.Request {
/// Represents a Query that can be fetched to a GraphQL Server.
/// For more information <see href="http://graphql.org/learn/serving-over-http/#post-request"/>
/// </summary>
public class GraphQLRequest : IEquatable<GraphQLRequest> {
public class GraphQLRequest : IEquatable<GraphQLRequest?> {

/// <summary>
/// The Query
Expand All @@ -17,50 +18,40 @@ public class GraphQLRequest : IEquatable<GraphQLRequest> {
/// <summary>
/// If the provided <see cref="Query"/> contains multiple named operations, this specifies which operation should be executed.
/// </summary>
public string OperationName { get; set; }
public string? OperationName { get; set; }

/// <summary>
/// The Variables
/// </summary>
public dynamic Variables { get; set; }
public dynamic? Variables { get; set; }

/// <summary>
/// Initialize a new GraphQLRequest
/// </summary>
/// <param name="query">The Query</param>
public GraphQLRequest(string query){
this.Query = query;
}

/// <inheritdoc />
public override bool Equals(object obj) => this.Equals(obj as GraphQLRequest);
public override bool Equals(object? obj) => this.Equals(obj as GraphQLRequest);

/// <inheritdoc />
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<GraphQLRequest>.Default.Equals(this, other);
}

/// <inheritdoc />
public override int GetHashCode() {
var hashCode = -689803966;
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(this.Query);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(this.OperationName);
hashCode = hashCode * -1521134295 + EqualityComparer<dynamic>.Default.GetHashCode(this.Variables);
return hashCode;
}
public override int GetHashCode() => EqualityComparer<GraphQLRequest>.Default.GetHashCode(this);

/// <inheritdoc />
public static bool operator ==(GraphQLRequest request1, GraphQLRequest request2) => EqualityComparer<GraphQLRequest>.Default.Equals(request1, request2);
public static bool operator ==(GraphQLRequest? request1, GraphQLRequest? request2) => EqualityComparer<GraphQLRequest?>.Default.Equals(request1, request2);

/// <inheritdoc />
public static bool operator !=(GraphQLRequest request1, GraphQLRequest request2) => !(request1 == request2);
public static bool operator !=(GraphQLRequest? request1, GraphQLRequest? request2) => !(request1 == request2);

}

Expand Down
21 changes: 8 additions & 13 deletions tests/GraphQL.Client.Tests/GraphQLClientGetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -36,7 +33,7 @@ query Planet {
planet(planetID: ""1"") {
name
}
}",
}") {
OperationName = "Person"
};
var response = await this.GraphQLClient.GetAsync(graphQLRequest).ConfigureAwait(false);
Expand All @@ -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"
}
Expand All @@ -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
Expand All @@ -78,7 +73,7 @@ query Planet {
planet(planetID: ""1"") {
name
}
}",
}"){
OperationName = "Person",
Variables = new {
personId = "1"
Expand Down
29 changes: 11 additions & 18 deletions tests/GraphQL.Client.Tests/GraphQLClientPostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,28 @@ 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);
Assert.Equal("Luke Skywalker", response.GetDataFieldAs<Person>("person").Name);
}

[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);

Expand All @@ -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
Expand All @@ -56,7 +51,7 @@ query Planet {
planet(planetID: ""1"") {
name
}
}",
}") {
OperationName = "Person"
};
var response = await this.GraphQLClient.PostAsync(graphQLRequest).ConfigureAwait(false);
Expand All @@ -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"
}
Expand All @@ -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
Expand All @@ -98,7 +91,7 @@ query Planet {
planet(planetID: ""1"") {
name
}
}",
}") {
OperationName = "Person",
Variables = new {
personId = "1"
Expand Down
Loading