Skip to content

Can GraphQLResponse<T> implement an IGraphQLResponse non-generic interface? #224

@BillBaird

Description

@BillBaird

With changes from 2.0 GraphQLResponse to 3.0 GraphQLResponse<T>, common error handling logic must use generics even though the Errors and Extensions have no need for the generic type T. In my case, I have various common client error handling logic that had to be unnecessarily extended to work with generics.

I propose something like:

public interface IGraphQLReadOnlyResponse
{
    public object Data { get; }
    public GraphQLError[]? Errors { get; }
    public Map? Extensions { get; }
}

I'm less interested in the Data property as an object (explicit interface implementation) than I am for Errors and Extensions. Providing a interface which allows these to be used by utility code that didn't know or care about, or even have visibility to the type T would allow the utility code to provide a consistent way of handling the errors simply by passing the GraphQLResponse to the error handler without regard to the generic type T.

For instance:

public void HandleErrors(IGraphQLReadOnlyResponse response)
{
    if (response.Errors ...)
}
...
var response = await client.SendQueryAsync<MyType>( ... );
HandleErrors(response);

Can this simple change be included? It would allow me to remove unnecessary complexity from client logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions