From 875520a3804e6a70967ec94fd809512e9772980b Mon Sep 17 00:00:00 2001 From: Adam Williams Date: Tue, 16 Apr 2024 09:14:35 +0100 Subject: [PATCH] Address #630 (#631) * Address #630 * Multi-framework build for primitives project * PR feedback: extension methods --- .../GraphQL.Client.Abstractions.csproj | 2 +- .../GraphQLClientExtensions.cs | 6 ++++-- .../GraphQL.Primitives.csproj | 2 +- src/GraphQL.Primitives/GraphQLRequest.cs | 5 ++++- src/GraphQL.Primitives/StringSyntaxAttribute.cs | 17 +++++++++++++++++ 5 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 src/GraphQL.Primitives/StringSyntaxAttribute.cs diff --git a/src/GraphQL.Client.Abstractions/GraphQL.Client.Abstractions.csproj b/src/GraphQL.Client.Abstractions/GraphQL.Client.Abstractions.csproj index 58f116f2..a18177ca 100644 --- a/src/GraphQL.Client.Abstractions/GraphQL.Client.Abstractions.csproj +++ b/src/GraphQL.Client.Abstractions/GraphQL.Client.Abstractions.csproj @@ -2,7 +2,7 @@ Abstractions for GraphQL.Client - netstandard2.0 + netstandard2.0;net7.0;net8.0 diff --git a/src/GraphQL.Client.Abstractions/GraphQLClientExtensions.cs b/src/GraphQL.Client.Abstractions/GraphQLClientExtensions.cs index e27d1a9a..cce6db1a 100644 --- a/src/GraphQL.Client.Abstractions/GraphQLClientExtensions.cs +++ b/src/GraphQL.Client.Abstractions/GraphQLClientExtensions.cs @@ -1,9 +1,11 @@ +using System.Diagnostics.CodeAnalysis; + namespace GraphQL.Client.Abstractions; public static class GraphQLClientExtensions { public static Task> SendQueryAsync(this IGraphQLClient client, - string query, object? variables = null, + [StringSyntax("GraphQL")] string query, object? variables = null, string? operationName = null, Func defineResponseType = null, CancellationToken cancellationToken = default) { _ = defineResponseType; @@ -12,7 +14,7 @@ public static Task> SendQueryAsync(this IG } public static Task> SendMutationAsync(this IGraphQLClient client, - string query, object? variables = null, + [StringSyntax("GraphQL")] string query, object? variables = null, string? operationName = null, Func defineResponseType = null, CancellationToken cancellationToken = default) { _ = defineResponseType; diff --git a/src/GraphQL.Primitives/GraphQL.Primitives.csproj b/src/GraphQL.Primitives/GraphQL.Primitives.csproj index 676e6fe8..b49b7360 100644 --- a/src/GraphQL.Primitives/GraphQL.Primitives.csproj +++ b/src/GraphQL.Primitives/GraphQL.Primitives.csproj @@ -3,7 +3,7 @@ GraphQL basic types GraphQL - netstandard2.0 + netstandard2.0;net7.0;net8.0 diff --git a/src/GraphQL.Primitives/GraphQLRequest.cs b/src/GraphQL.Primitives/GraphQLRequest.cs index f33ed88a..7aecb656 100644 --- a/src/GraphQL.Primitives/GraphQLRequest.cs +++ b/src/GraphQL.Primitives/GraphQLRequest.cs @@ -1,3 +1,5 @@ +using System.Diagnostics.CodeAnalysis; + namespace GraphQL; /// @@ -13,6 +15,7 @@ public class GraphQLRequest : Dictionary, IEquatable /// The Query /// + [StringSyntax("GraphQL")] public string Query { get => TryGetValue(QUERY_KEY, out object value) ? (string)value : null; @@ -48,7 +51,7 @@ public object? Variables public GraphQLRequest() { } - public GraphQLRequest(string query, object? variables = null, string? operationName = null, Dictionary? extensions = null) + public GraphQLRequest([StringSyntax("GraphQL")] string query, object? variables = null, string? operationName = null, Dictionary? extensions = null) { Query = query; Variables = variables; diff --git a/src/GraphQL.Primitives/StringSyntaxAttribute.cs b/src/GraphQL.Primitives/StringSyntaxAttribute.cs new file mode 100644 index 00000000..8ea74c0e --- /dev/null +++ b/src/GraphQL.Primitives/StringSyntaxAttribute.cs @@ -0,0 +1,17 @@ +#if !NET7_0_OR_GREATER + +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Stub +/// +public sealed class StringSyntaxAttribute : Attribute +{ + public const string CompositeFormat = nameof(CompositeFormat); + + public StringSyntaxAttribute(string syntax) + { + } + +} +#endif