Skip to content

Instantly share code, notes, and snippets.

@MBehtemam
Created December 1, 2018 07:55
Show Gist options
  • Save MBehtemam/d3417ead46b9a362a337238427a2720a to your computer and use it in GitHub Desktop.
Save MBehtemam/d3417ead46b9a362a337238427a2720a to your computer and use it in GitHub Desktop.
TodoQuery.cs
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