Skip to content

Commit b3245af

Browse files
committed
Add GetExtension method to GraphQLErrorsException and GraphQLResponse; update Serializer.Deserialize method signature
1 parent d6aa7b0 commit b3245af

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

GraphQLSharp/Client/Exceptions/GraphQLErrorsException.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,12 @@ public GraphQLErrorsException(GraphQLRequest request, HttpResponse httpResponse,
1818
this.errors = errors;
1919
this.extensions = extensions;
2020
}
21+
22+
public TExtension GetExtension<TExtension>(string key)
23+
{
24+
if (extensions == null || !extensions.TryGetValue(key, out var element))
25+
return default;
26+
27+
return Serializer.Deserialize<TExtension>(element.GetRawText());
28+
}
2129
}

GraphQLSharp/Client/Response/GraphQLResponse.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ public void ThrowIfAnyError()
2222
if (errors?.Count > 0)
2323
throw new GraphQLErrorsException(Request, HttpResponse, errors, extensions);
2424
}
25+
26+
public TExtension GetExtension<TExtension>(string key)
27+
{
28+
if (extensions == null || !extensions.TryGetValue(key, out var element))
29+
return default;
30+
31+
return Serializer.Deserialize<TExtension>(element.GetRawText());
32+
}
2533
}

GraphQLSharp/GraphQLSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PackageProjectUrl>https://github.com/Wish-Org/GraphQLSharp</PackageProjectUrl>
55
<RepositoryUrl>https://github.com/Wish-Org/GraphQLSharp</RepositoryUrl>
66
<Description>.NET Client for GraphQL - Modern and fast</Description>
7-
<Version>2.9.6</Version>
7+
<Version>2.9.7</Version>
88
<PackageTags>graphql;client;graphql-client;graphql-generator</PackageTags>
99
<Authors>Wish-Org</Authors>
1010
<PackageReadmeFile>README.md</PackageReadmeFile>

GraphQLSharp/Serialization/Serializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static string Serialize(object obj)
3030
return JsonSerializer.Deserialize(json, type, Options);
3131
}
3232

33-
public static T? Deserialize<T>(string json) where T : class
33+
public static T? Deserialize<T>(string json)
3434
{
3535
return JsonSerializer.Deserialize<T>(json, Options);
3636
}

0 commit comments

Comments
 (0)