Skip to content

Commit 496927b

Browse files
authored
Serialize extensions in tests and only non-null values (#785)
1 parent 31ca5e9 commit 496927b

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

tests/Samples.Server.Tests/Serializer.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,41 @@ internal static FormUrlEncodedContent ToFormUrlEncodedContent(GraphQLRequest req
3939
dictionary["variables"] = ToJson(request.Variables);
4040
}
4141

42+
if (request.Extensions != null)
43+
{
44+
dictionary["extensions"] = ToJson(request.Extensions);
45+
}
46+
4247
return new FormUrlEncodedContent(dictionary);
4348
}
4449

4550
internal static Task<string> ToQueryStringParamsAsync(GraphQLRequest request)
4651
=> ToFormUrlEncodedContent(request).ReadAsStringAsync();
4752

4853
private static Dictionary<string, object> ToDictionary(this GraphQLRequest request)
49-
=> new Dictionary<string, object>
54+
{
55+
var dictionary = new Dictionary<string, object>();
56+
57+
if (request.OperationName != null)
58+
{
59+
dictionary["operationName"] = request.OperationName;
60+
}
61+
62+
if (request.Query != null)
5063
{
51-
{ "operationName", request.OperationName },
52-
{ "query", request.Query },
53-
{ "variables", request.Variables }
54-
};
64+
dictionary["query"] = request.Query;
65+
}
66+
67+
if (request.Variables != null)
68+
{
69+
dictionary["variables"] = request.Variables;
70+
}
71+
72+
if (request.Extensions != null)
73+
{
74+
dictionary["extensions"] = request.Extensions;
75+
}
76+
77+
return dictionary;
78+
}
5579
}

0 commit comments

Comments
 (0)