public BookType(IBooksDataSource booksDataSource) { Name = "Book"; Field(b => b.Id).Description("The id of the book."); Field(b => b.CacheId).Description("The cache id of the book."); Field(b => b.Name).Description("The name of the book."); Field(b => b.Authors).Description("The authors of the book."); }
public BookType(IBooksDataSource booksDataSource, IAuthorsDataSource authorsDataSource) { Name = "Book"; Field(b => b.Id).Description("The id of the book."); Field(b => b.Name).Description("The name of the book."); Field <AuthorType>( "author", resolve: context => authorsDataSource.GetAuthor(context.Source.AuthorId) ); }
public Mutation(IBooksDataSource booksDataSource) { Name = "Mutation"; Field <BookType>( "newBook", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <BookInputType> > { Name = "book" } ), resolve: context => { var book = context.GetArgument <Book>("book"); return(booksDataSource.NewBook(book)); }); Field <BookType>( "editBook", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id" }, new QueryArgument <NonNullGraphType <BookInputType> > { Name = "book" } ), resolve: context => { var id = context.GetArgument <int>("id"); var book = context.GetArgument <Book>("book"); book.Id = id; return(booksDataSource.EditBook(book)); }); Field <BooleanGraphType>( "delete", arguments: new QueryArguments( new QueryArgument <StringGraphType> { Name = "id" } ), resolve: context => { var id = context.GetArgument <string>("id"); if (int.TryParse(id, out int idValue)) { return(booksDataSource.DeleteBook(idValue)); } return(false); }); }
public AuthorType(IBooksDataSource booksDataSource, IAuthorsDataSource authorsDataSource) { Name = "Author"; Field(a => a.Id).Description("The id of the author."); Field(a => a.Name).Description("The name of the author."); Field(a => a.Email).Description("The email of the author."); Field <ListGraphType <BookType> >( "books", resolve: context => booksDataSource.GetBooksByAuthor(context.Source.Id) ); }
public Query(IBooksDataSource booksDataSource) { Name = "Query"; Field <BookType>( "book", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id", Description = "id of the book" } ), resolve: context => booksDataSource.GetBook(context.GetArgument <int>("id")) ); Field <StringGraphType>( "source", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id", Description = "id of the markdown source" } ), resolve: context => MarkdownHelper.GetMarkdown(context.GetArgument <string>("id")) ); Field <ListGraphType <BookType> >( "books", arguments: new QueryArguments( new QueryArgument <IntGraphType> { Name = "from", Description = "first pagination index" }, new QueryArgument <IntGraphType> { Name = "to", Description = "last pagination index" } ), resolve: context => booksDataSource.GetBooks() ); Field <IntGraphType>( "total", resolve: context => booksDataSource.GetBooks().Count ); }
public Query(IBooksDataSource booksDataSource, IAuthorsDataSource authorsDataSource) { Name = "Query"; Field <BookType>( "book", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id", Description = "id of the book" } ), resolve: context => booksDataSource.GetBook(context.GetArgument <int>("id")) ); Field <StringGraphType>( "bookSource", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id", Description = "id of the book" } ), resolve: context => JsonConvert.SerializeObject(booksDataSource.GetBook(context.GetArgument <int>("id"))) ); Field <ListGraphType <BookType> >( "books", resolve: context => booksDataSource.GetBooks() ); Field <IntGraphType>( "booksCount", resolve: context => booksDataSource.GetBooks().Count ); Field <AuthorType>( "author", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id", Description = "id of the author" } ), resolve: context => authorsDataSource.GetAuthor(context.GetArgument <int>("id")) ); Field <StringGraphType>( "authorSource", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id", Description = "id of the author" } ), resolve: context => JsonConvert.SerializeObject(authorsDataSource.GetAuthor(context.GetArgument <int>("id"))) ); Field <ListGraphType <AuthorType> >( "authors", resolve: context => authorsDataSource.GetAuthors() ); Field <IntGraphType>( "authorsCount", resolve: context => authorsDataSource.GetAuthors().Count ); }
public Mutation(IBooksDataSource booksDataSource, IAuthorsDataSource authorsDataSource) { Name = "Mutation"; Field <BookType>( "newBook", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <BookInputType> > { Name = "book" } ), resolve: context => { var book = context.GetArgument <Book>("book"); return(booksDataSource.NewBook(book)); }); Field <BookType>( "editBook", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id" }, new QueryArgument <NonNullGraphType <BookInputType> > { Name = "book" } ), resolve: context => { var id = context.GetArgument <int>("id"); var book = context.GetArgument <Book>("book"); book.Id = id; return(booksDataSource.EditBook(book)); }); Field <BooleanGraphType>( "deleteBook", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id" } ), resolve: context => { var id = context.GetArgument <int>("id"); return(booksDataSource.DeleteBook(id)); }); Field <AuthorType>( "newAuthor", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <AuthorInputType> > { Name = "author" } ), resolve: context => { var author = context.GetArgument <Author>("author"); return(authorsDataSource.NewAuthor(author)); }); Field <AuthorType>( "editAuthor", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id" }, new QueryArgument <NonNullGraphType <AuthorInputType> > { Name = "author" } ), resolve: context => { var id = context.GetArgument <int>("id"); var author = context.GetArgument <Author>("author"); author.Id = id; return(authorsDataSource.EditAuthor(author)); }); Field <BooleanGraphType>( "deleteAuthor", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id" } ), resolve: context => { var id = context.GetArgument <int>("id"); return(authorsDataSource.DeleteAuthor(id)); }); }
public Query(IBooksDataSource booksDataSource, IAuthorsDataSource authorsDataSource, IHttpContextAccessor contextAccessor) { this.contextAccessor = contextAccessor; this.authorsDataSource = authorsDataSource; this.booksDataSource = booksDataSource; }