Exemplo n.º 1
0
 public AuthorDeletedSubscription(IAuthorMessageService authorMessageService)
 {
     Name       = "authorDeleted";
     Type       = typeof(AuthorType);
     Resolver   = new FuncFieldResolver <Author>(c => c.Source as Author);
     Subscriber = new EventStreamResolver <Author>(c => authorMessageService.GetAuthorDeletedMessages());
 }
Exemplo n.º 2
0
        public BooksMutation(IBookRepository bookRepository, IAuthorRepository authorRepository, IAuthorMessageService authorMessageService, IBookMessageService bookMessageService)
        {
            FieldAsync <BookType>(
                "createBook",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <BookAddedType> > {
                Name = "book"
            }),
                resolve: async context =>
            {
                var book = context.GetArgument <Book>("book");
                await bookRepository.AddBookAsync(book);
                bookMessageService.AddBookMessage(book);
                return(book);
            });

            FieldAsync <BookType>(
                "updateBook",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <BookUpdatedType> > {
                Name = "book"
            }),
                resolve: async context =>
            {
                var book = context.GetArgument <Book>("book");
                await bookRepository.UpdateBookAsync(book);
                bookMessageService.UpdateBookMessage(book);
                return(book);
            });

            FieldAsync <BookType>(
                "deleteBook",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }),
                resolve: async context =>
            {
                var id   = context.GetArgument <int>("id");
                var book = await bookRepository.GetBookAsync(id);
                await bookRepository.DeleteBookAsync(book);
                bookMessageService.DeleteBookMessage(book);
                return(book);
            });

            FieldAsync <AuthorType>(
                "createAuthor",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <AuthorAddedType> > {
                Name = "author"
            }),
                resolve: async context =>
            {
                var author = context.GetArgument <Author>("author");
                await authorRepository.AddAuthorAsync(author);
                authorMessageService.AddAuthorMessage(author);
                return(author);
            });

            FieldAsync <AuthorType>(
                "updateAuthor",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <BookUpdatedType> > {
                Name = "author"
            }),
                resolve: async context =>
            {
                var author = context.GetArgument <Author>("author");
                await authorRepository.UpdateAuthorAsync(author);
                authorMessageService.UpdateAuthorMessage(author);
                return(author);
            });


            FieldAsync <AuthorType>(
                "deleteAuthor",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }),
                resolve: async context =>
            {
                var id     = context.GetArgument <int>("id");
                var author = await authorRepository.GetAuthorAsync(id);
                await authorRepository.DeleteAuthorAsync(author);
                authorMessageService.DeleteAuthorMessage(author);
                return(author);
            });
        }