示例#1
0
        public AuthorQuery(ODataGraphQLDbContext dbContext)
        {
            Field <AuthorType>(
                "Author",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id", Description = "The ID of the Author."
            }),
                resolve: context =>
            {
                var id     = context.GetArgument <int>("id");
                var author = dbContext
                             .Author
                             .Include(a => a.Books)
                             .FirstOrDefault(i => i.Id == id);
                return(author);
            });

            Field <ListGraphType <AuthorType> >(
                "Authors",
                resolve: context =>
            {
                var authors = dbContext.Author.Include(a => a.Books);
                return(authors);
            });
        }
示例#2
0
 public GraphQLController(ODataGraphQLDbContext dbContext) => _dbContext = dbContext;