Created
December 30, 2021 11:42
-
-
Save nelsonprsousa/c6783d9711b71b9e8855bd9754dc377e to your computer and use it in GitHub Desktop.
Tempt 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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