Skip to content

Instantly share code, notes, and snippets.

@nelsonprsousa
Created December 30, 2021 11:10
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/a5b7b53cdf2df42732d579a54af9f924 to your computer and use it in GitHub Desktop.
Save nelsonprsousa/a5b7b53cdf2df42732d579a54af9f924 to your computer and use it in GitHub Desktop.
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