Some GraphQL servers, such as those based on current versions of Hot Chocolate, only respond with application/graphql-response+json. In this case, the server may respond with various 4xx status codes, expecting the client to parse them. This is noted in the source code. However, any status code that is not 2xx or 400 is rejected.
|
/// <summary> |
|
/// Delegate to determine if GraphQL response may be properly deserialized into <see cref="GraphQLResponse{T}"/>. |
|
/// Note that compatible to the draft graphql-over-http spec GraphQL Server MAY return 4xx status codes (401/403, etc.) |
|
/// with well-formed GraphQL response containing errors collection. |
|
/// </summary> |
|
public Func<HttpResponseMessage, bool> IsValidResponseToDeserialize { get; set; } = DefaultIsValidResponseToDeserialize; |
|
|
|
private static readonly IReadOnlyCollection<string> _acceptedResponseContentTypes = new[] { "application/graphql+json", "application/json", "application/graphql-response+json" }; |
|
|
|
public static bool DefaultIsValidResponseToDeserialize(HttpResponseMessage r) |
|
{ |
|
if (r.Content.Headers.ContentType?.MediaType != null && !_acceptedResponseContentTypes.Contains(r.Content.Headers.ContentType.MediaType)) |
|
return false; |
|
|
|
return r.IsSuccessStatusCode || r.StatusCode == HttpStatusCode.BadRequest; |
|
} |
This shouldn't matter most of the time for servers that support application/json per the GraphQL over HTTP draft spec, since the default Accept header is set to application/json, and the server should return 200 for all responses that can be parsed with that content type.
Some GraphQL servers, such as those based on current versions of Hot Chocolate, only respond with
application/graphql-response+json. In this case, the server may respond with various 4xx status codes, expecting the client to parse them. This is noted in the source code. However, any status code that is not 2xx or 400 is rejected.graphql-client/src/GraphQL.Client/GraphQLHttpClientOptions.cs
Lines 63 to 78 in 6236c9b
This shouldn't matter most of the time for servers that support
application/jsonper the GraphQL over HTTP draft spec, since the default Accept header is set toapplication/json, and the server should return 200 for all responses that can be parsed with that content type.