Skip to content

Commit 546f570

Browse files
committed
add stringsyntaxattribute to constructor of GraphQLHttpRequest, ad "QL" abbreviation to resharper dictionary
1 parent 6d1c010 commit 546f570

File tree

2 files changed

+52
-49
lines changed

2 files changed

+52
-49
lines changed

GraphQL.Client.sln.DotSettings

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QL/@EntryIndexedValue">QL</s:String></wpf:ResourceDictionary>
+50-49
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
1-
#pragma warning disable IDE0005
2-
// see https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/implicit-global-using-netfx
3-
using System.Net.Http;
4-
#pragma warning restore IDE0005
5-
using System.Net.Http.Headers;
6-
using System.Text;
7-
using GraphQL.Client.Abstractions;
8-
9-
namespace GraphQL.Client.Http;
10-
11-
public class GraphQLHttpRequest : GraphQLRequest
12-
{
13-
public GraphQLHttpRequest()
14-
{
15-
}
16-
17-
public GraphQLHttpRequest(string query, object? variables = null, string? operationName = null, Dictionary<string, object?>? extensions = null)
18-
: base(query, variables, operationName, extensions)
19-
{
20-
}
21-
22-
public GraphQLHttpRequest(GraphQLRequest other)
23-
: base(other)
24-
{
25-
}
26-
27-
/// <summary>
28-
/// Creates a <see cref="HttpRequestMessage"/> from this <see cref="GraphQLHttpRequest"/>.
29-
/// Used by <see cref="GraphQLHttpClient"/> to convert GraphQL requests when sending them as regular HTTP requests.
30-
/// </summary>
31-
/// <param name="options">the <see cref="GraphQLHttpClientOptions"/> passed from <see cref="GraphQLHttpClient"/></param>
32-
/// <param name="serializer">the <see cref="IGraphQLJsonSerializer"/> passed from <see cref="GraphQLHttpClient"/></param>
33-
/// <returns></returns>
34-
public virtual HttpRequestMessage ToHttpRequestMessage(GraphQLHttpClientOptions options, IGraphQLJsonSerializer serializer)
35-
{
36-
var message = new HttpRequestMessage(HttpMethod.Post, options.EndPoint)
37-
{
38-
Content = new StringContent(serializer.SerializeToString(this), Encoding.UTF8, options.MediaType)
39-
};
40-
message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/graphql-response+json"));
41-
message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
1+
#pragma warning disable IDE0005
2+
// see https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/implicit-global-using-netfx
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Net.Http;
5+
#pragma warning restore IDE0005
6+
using System.Net.Http.Headers;
7+
using System.Text;
8+
using GraphQL.Client.Abstractions;
9+
10+
namespace GraphQL.Client.Http;
11+
12+
public class GraphQLHttpRequest : GraphQLRequest
13+
{
14+
public GraphQLHttpRequest()
15+
{
16+
}
17+
18+
public GraphQLHttpRequest([StringSyntax("GraphQL")] string query, object? variables = null, string? operationName = null, Dictionary<string, object?>? extensions = null)
19+
: base(query, variables, operationName, extensions)
20+
{
21+
}
22+
23+
public GraphQLHttpRequest(GraphQLRequest other)
24+
: base(other)
25+
{
26+
}
27+
28+
/// <summary>
29+
/// Creates a <see cref="HttpRequestMessage"/> from this <see cref="GraphQLHttpRequest"/>.
30+
/// Used by <see cref="GraphQLHttpClient"/> to convert GraphQL requests when sending them as regular HTTP requests.
31+
/// </summary>
32+
/// <param name="options">the <see cref="GraphQLHttpClientOptions"/> passed from <see cref="GraphQLHttpClient"/></param>
33+
/// <param name="serializer">the <see cref="IGraphQLJsonSerializer"/> passed from <see cref="GraphQLHttpClient"/></param>
34+
/// <returns></returns>
35+
public virtual HttpRequestMessage ToHttpRequestMessage(GraphQLHttpClientOptions options, IGraphQLJsonSerializer serializer)
36+
{
37+
var message = new HttpRequestMessage(HttpMethod.Post, options.EndPoint)
38+
{
39+
Content = new StringContent(serializer.SerializeToString(this), Encoding.UTF8, options.MediaType)
40+
};
41+
message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/graphql-response+json"));
42+
message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
4243
message.Headers.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8"));
4344

4445
// Explicitly setting content header to avoid issues with some GrahQL servers
45-
message.Content.Headers.ContentType = new MediaTypeHeaderValue(options.MediaType);
46-
47-
if (options.DefaultUserAgentRequestHeader != null)
48-
message.Headers.UserAgent.Add(options.DefaultUserAgentRequestHeader);
49-
50-
return message;
51-
}
52-
}
46+
message.Content.Headers.ContentType = new MediaTypeHeaderValue(options.MediaType);
47+
48+
if (options.DefaultUserAgentRequestHeader != null)
49+
message.Headers.UserAgent.Add(options.DefaultUserAgentRequestHeader);
50+
51+
return message;
52+
}
53+
}

0 commit comments

Comments
 (0)