Created
December 30, 2021 11:10
-
-
Save nelsonprsousa/a5b7b53cdf2df42732d579a54af9f924 to your computer and use it in GitHub Desktop.
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 HotChocolate.Types.Pagination; | |
[ExtendObjectType(OperationTypeNames.Query)] | |
[GraphQLName(nameof(TodoQuery))] | |
public class TodoQuery | |
{ | |
[UsePaging] | |
public Connection<ITodoResult> GetTodos(string? after, int? first) | |
{ | |
IEnumerable<ITodoResult> todos = new List<Todo>() | |
{ | |
new Todo() { Id = "1" }, | |
new Todo() { Id = "2" }, | |
}; | |
var edges = todos.Select(todo => new Edge<ITodoResult>(todo, "1")).ToList(); | |
var pageInfo = new ConnectionPageInfo(false, false, null, null); | |
var connection = new Connection<ITodoResult>( | |
edges, | |
pageInfo, | |
ct => ValueTask.FromResult(0)); | |
return connection; | |
} | |
[UnionType("TodoResult")] | |
public interface ITodoResult | |
{ | |
} | |
public class Todo : ITodoResult | |
{ | |
public string Id { get; set; } = default!; | |
} | |
public class TodoError : ITodoResult | |
{ | |
public string Message { get; set; } = "Error message here"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment