Created
December 1, 2018 07:55
-
-
Save MBehtemam/d3417ead46b9a362a337238427a2720a to your computer and use it in GitHub Desktop.
TodoQuery.cs
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
using System; | |
using GraphQL.Types; | |
using GraphQL; | |
using TodoAPI.Data; | |
namespace TodoAPI.Models | |
{ | |
public class TodoQuery : ObjectGraphType | |
{ | |
public TodoQuery(ITodoRepository todoRepository) | |
{ | |
Field<TodoType>("todo", arguments: new QueryArguments( | |
new QueryArgument<NonNullGraphType<IntGraphType>> { Name = "id", Description = "id of todo" } | |
), | |
resolve: context => todoRepository.GetTodoById(context.GetArgument<int>("id")).Result | |
); | |
Field<ListGraphType<TodoType>>("todos", | |
resolve: context => todoRepository.GetTodos().Result | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment