コード例 #1
0
        public TodosQuery(ITodosService todos)
        {
            Name = "Query";
            Field <ListGraphType <TodoType> >(
                "todos",
                arguments: new QueryArguments(
                    new QueryArgument <StringGraphType> {
                Name = "todoId"
            },
                    new QueryArgument <IntGraphType> {
                Name = "offset"
            },
                    new QueryArgument <IntGraphType> {
                Name = "limit"
            }),
                resolve: context =>
            {
                var todoId = context.GetArgument <string>("todoId");
                var offset = context.GetArgument <int>("offset");
                var limit  = context.GetArgument <int>("limit");

                if (todoId == null)
                {
                    return(todos.GetTodosAsync(offset, limit));
                }

                //TODO: clean this up
                return(Task.FromResult(new List <Todo> {
                    todos.GetTodoByIdAsync(todoId).Result
                }.AsEnumerable()));
            });
        }
コード例 #2
0
        public TodosMutation(ITodosService todos)
        {
            Name = "Mutation";
            Field <TodoType>(
                "createTodo",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <TodoCreateInputType> > {
                Name = "todo"
            }),
                resolve: context =>
            {
                var todoInput = context.GetArgument <TodoCreateInput>("todo");
                var id        = Guid.NewGuid().ToString();
                var todo      = new Todo(id, todoInput.Description, todoInput.Complete);

                return(todos.CreateAsync(todo));
            }
                );
            Field <TodoType>(
                "updateTodo",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <TodoUpdateInputType> > {
                Name = "todo"
            }),
                resolve: context =>
            {
                var todoInput = context.GetArgument <TodoUpdateInput>("todo");
                var todo      = new Todo(todoInput.Id, todoInput.Description, todoInput.Complete);

                return(todos.UpdateAsync(todo));
            }
                );
            FieldAsync <TodoType>(
                "completeTodo",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "todoId"
            }),
                resolve: async context =>
            {
                var todoId = context.GetArgument <string>("todoId");
                return(await context.TryAsyncResolve(async c => await todos.CompleteAsync(todoId)));
            }
                );
        }
コード例 #3
0
 public TodosController(ITodosService todosService)
 {
     _todosService = todosService;
 }
コード例 #4
0
 public TodosController(IMapper mapper, ITodosService todosService, ILogger <TodosController> logger)
 {
     _mapper       = mapper;
     _todosService = todosService;
     _logger       = logger;
 }
コード例 #5
0
ファイル: TodoType.cs プロジェクト: sergione/todoapp
 public TodoType(ITodosService todos)
 {
     Field(x => x.Id);
     Field(x => x.Description);
     Field(x => x.Complete);
 }
コード例 #6
0
 public TodosController(ITodosService todos)
 {
     _todos = todos;
 }
コード例 #7
0
 public TodosViewModel(ITodosService todosService)
 {
     _todosService = todosService;
 }
コード例 #8
0
 public TodosController(ITodosService service)
 {
     todosService = service;
 }
コード例 #9
0
 public TodosController(ITodosService todosService) =>
 this.todosService = todosService;
コード例 #10
0
 public TodosPresenter(ITodosView view, ITodosService todosService, List <Todo> items = null)
 {
     _view         = view;
     _todosService = todosService;
     Items         = items ?? Enumerable.Empty <Todo>().ToList();
 }