-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get the original Http Response? #527
Comments
I think this points out that GraphQL server is misconfigured and returns plain text response instead of one required by the spec. I see use uses GraphQL.NET as server. Could you provide your server startup configuration code ( |
Regarding your second question - for now you may use |
easier said than done: the responsestream was already consumed inside IsValidResponseToDeserialize |
I was able to help myself by encapsulating the serializer like this: public class DebugSerializer : IGraphQLWebsocketJsonSerializer {
NewtonsoftJsonSerializer impl = new();
public byte[] SerializeToBytes(GraphQLWebSocketRequest request)
=> impl.SerializeToBytes(request);
public Task<WebsocketMessageWrapper> DeserializeToWebsocketResponseWrapperAsync(Stream stream)
=> impl.DeserializeToWebsocketResponseWrapperAsync(stream);
public GraphQLWebSocketResponse<TResponse> DeserializeToWebsocketResponse<TResponse>(byte[] bytes)
=> impl.DeserializeToWebsocketResponse<TResponse>(bytes);
public string SerializeToString(GraphQLRequest request)
=> impl.SerializeToString(request);
public Task<GraphQLResponse<TResponse>> DeserializeFromUtf8StreamAsync<TResponse>(Stream stream, CancellationToken cancellationToken) {
using (var sr = new StreamReader(stream, Encoding.UTF8)) {
var res = sr.ReadToEnd();
Console.WriteLine(res);
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(res)))
return impl.DeserializeFromUtf8StreamAsync<TResponse>(ms, cancellationToken);
}
}
} And use it instead of the default: var api = new GraphQLHttpClient(
"https://my.service/ql",
new DebugSerializer());
var res = await api.SendMutationAsync(...); |
I don't have access to the server it's a third party service. |
Are you putting the |
Sometimes I make graphQL requests using graphQL client but the server returns something like this:
"GraphQL.Validation.InvalidVariableError: Variable '$filter' is invalid. Unrecognized input fields 'operation' for type 'FilterGQLInputType'.\n at GraphQL.Validation.ValidationContext.<GetVariableValue>g__ParseValueObject|39_3(IInputObjectGraphType graphType, VariableDefinition variableDef, VariableName variableName, Object value, IVariableVisitor visitor) in /_/src/GraphQL/Validation/ValidationContext.cs:line 452\n at GraphQL.Validation.ValidationContext.<GetVariableValue>g__ParseValue|39_0(IGraphType type, VariableDefinition variableDef, VariableName variableName, Object value, IVariableVisitor visitor) in /_/src/GraphQL/Validation/ValidationContext.cs:line 297\n at GraphQL.Validation.ValidationContext.GetVariableValues(ISchema schema, VariableDefinitions variableDefinitions, Inputs inputs, IVariableVisitor visitor) in /_/src/GraphQL/Validation/ValidationContext.cs:line 231"
Obviously this won't be mapped or deserialized into any object and then graphQL throws an exception which is all good but I am unable to get the raw response all I get is the exception:
The JSON value could not be converted to GraphQL.GraphQLResponse1[ExtraEgypt.Models.Subsbase.CustomerQueryResponse]. Path: $ | LineNumber: 0 | BytePositionInLine: 895.
I would also like to get the original HTTP response (shown at the top) for logging purposes otherwise it becomes very difficult to understand what happened.
The text was updated successfully, but these errors were encountered: