Skip to content

Instantly share code, notes, and snippets.

@nelsonprsousa
Created December 30, 2021 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelsonprsousa/c6783d9711b71b9e8855bd9754dc377e to your computer and use it in GitHub Desktop.
Save nelsonprsousa/c6783d9711b71b9e8855bd9754dc377e to your computer and use it in GitHub Desktop.
Tempt 2
namespace Wanderlust.API.Presentation.Queries;
using System;
using System.Threading;
using HotChocolate.Types.Pagination;
[ExtendObjectType(OperationTypeNames.Query)]
[GraphQLName(nameof(TodoQuery))]
public class TodoQuery
{
[UsePaging]
public ITodoResult GetTodos(string? after, int? first)
{
IEnumerable<Todo> todos = new List<Todo>()
{
new Todo() { Id = "1" },
new Todo() { Id = "2" },
};
var edges = todos.Select(todo => new Edge<Todo>(todo, "1")).ToList();
var pageInfo = new ConnectionPageInfo(false, false, null, null);
var connection = new CustomConnection<Todo>(
edges,
pageInfo,
ct => ValueTask.FromResult(0));
var test = connection;
return test;
}
public class CustomConnection<T> : Connection<T>, ITodoResult
where T : Todo
{
public CustomConnection(IReadOnlyCollection<Edge<T>> edges, ConnectionPageInfo info, Func<CancellationToken, ValueTask<int>> getTotalCount)
: base(edges, info, getTotalCount)
{
}
}
public class TodoError : ITodoResult
{
public string Message { get; set; } = "Error message here";
}
public class Todo
{
public string Id { get; set; } = default!;
}
[UnionType("TodoResult")]
public interface ITodoResult
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment