forked from OrchardCMS/OrchardCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
105 changed files
with
1,155 additions
and
563 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 15 additions & 1 deletion
16
src/OrchardCore.Modules/OrchardCore.Admin/Views/Navbar.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLNamedQueryRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
|
||
using GraphQL.Transport; | ||
using OrchardCore.Apis.GraphQL.Queries; | ||
|
||
namespace OrchardCore.Apis.GraphQL | ||
{ | ||
public class GraphQLNamedQueryRequest : GraphQLRequest | ||
{ | ||
/// <summary> | ||
/// Used to store some graphql query on the server, and then the client only needs to submit the name of that query to reduce the size of the network request | ||
/// <see cref="INamedQueryProvider"/> | ||
/// </summary> | ||
public string NamedQuery { get; set; } | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
...rchardCore.Modules/OrchardCore.Apis.GraphQL/Json/GraphQLNamedQueryRequestJsonConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using GraphQL; | ||
|
||
namespace OrchardCore.Apis.GraphQL.Json; | ||
|
||
public class GraphQLNamedQueryRequestJsonConverter : JsonConverter<GraphQLNamedQueryRequest> | ||
{ | ||
public static readonly GraphQLNamedQueryRequestJsonConverter Instance = new(); | ||
|
||
/// <summary> | ||
/// Name for the operation name parameter. | ||
/// See https://github.com/graphql/graphql-over-http/blob/master/spec/GraphQLOverHTTP.md#request-parameters | ||
/// </summary> | ||
private const string _operationNameKey = "operationName"; | ||
|
||
/// <summary> | ||
/// Name for the query parameter. | ||
/// See https://github.com/graphql/graphql-over-http/blob/master/spec/GraphQLOverHTTP.md#request-parameters | ||
/// </summary> | ||
private const string _queryKey = "query"; | ||
|
||
/// <summary> | ||
/// Name for the variables parameter. | ||
/// See https://github.com/graphql/graphql-over-http/blob/master/spec/GraphQLOverHTTP.md#request-parameters | ||
/// </summary> | ||
private const string _variablesKey = "variables"; | ||
|
||
/// <summary> | ||
/// Name for the extensions parameter. | ||
/// See https://github.com/graphql/graphql-over-http/blob/master/spec/GraphQLOverHTTP.md#request-parameters | ||
/// </summary> | ||
private const string _extensionsKey = "extensions"; | ||
|
||
/// <summary> | ||
/// Name for the namedQuery parameter. | ||
/// </summary> | ||
private const string _namedQueryKey = "namedQuery"; | ||
|
||
public override void Write(Utf8JsonWriter writer, GraphQLNamedQueryRequest value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStartObject(); | ||
if (value.Query != null) | ||
{ | ||
writer.WritePropertyName(_queryKey); | ||
writer.WriteStringValue(value.Query); | ||
} | ||
|
||
if (value.OperationName != null) | ||
{ | ||
writer.WritePropertyName(_operationNameKey); | ||
writer.WriteStringValue(value.OperationName); | ||
} | ||
|
||
if (value.Variables != null) | ||
{ | ||
writer.WritePropertyName(_variablesKey); | ||
JsonSerializer.Serialize(writer, value.Variables, options); | ||
} | ||
|
||
if (value.Extensions != null) | ||
{ | ||
writer.WritePropertyName(_extensionsKey); | ||
JsonSerializer.Serialize(writer, value.Extensions, options); | ||
} | ||
|
||
if (value.NamedQuery != null) | ||
{ | ||
writer.WritePropertyName(_namedQueryKey); | ||
JsonSerializer.Serialize(writer, value.NamedQuery, options); | ||
} | ||
|
||
writer.WriteEndObject(); | ||
} | ||
|
||
public override GraphQLNamedQueryRequest Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType != JsonTokenType.StartObject) | ||
{ | ||
throw new JsonException(); | ||
} | ||
|
||
var request = new GraphQLNamedQueryRequest(); | ||
|
||
while (reader.Read()) | ||
{ | ||
if (reader.TokenType == JsonTokenType.EndObject) | ||
{ | ||
return request; | ||
} | ||
|
||
if (reader.TokenType != JsonTokenType.PropertyName) | ||
{ | ||
throw new JsonException(); | ||
} | ||
|
||
var key = reader.GetString()!; | ||
|
||
// Unexpected end of data. | ||
if (!reader.Read()) | ||
throw new JsonException(); | ||
|
||
switch (key) | ||
{ | ||
case _queryKey: | ||
request.Query = reader.GetString()!; | ||
break; | ||
case _operationNameKey: | ||
request.OperationName = reader.GetString()!; | ||
break; | ||
case _namedQueryKey: | ||
request.NamedQuery = reader.GetString(); | ||
break; | ||
case _variablesKey: | ||
request.Variables = JsonSerializer.Deserialize<Inputs>(ref reader, options); | ||
break; | ||
case _extensionsKey: | ||
request.Extensions = JsonSerializer.Deserialize<Inputs>(ref reader, options); | ||
break; | ||
default: | ||
reader.Skip(); | ||
break; | ||
} | ||
} | ||
|
||
// Unexpected end of data. | ||
throw new JsonException(); | ||
} | ||
} |
Oops, something went wrong.