Beispiel #1
0
        public AuthorQuery(AuthorData authorData)//ApplicationDbContext db)
        {
            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 = db
                //     .Authors
                //     .Include(a => a.Books)
                //     .FirstOrDefault(i => i.Id == id);
                //   return author;
                return(authorData.authors.FirstOrDefault(x => x.Id == id));
            });

            Field <ListGraphType <AuthorType> >(
                "Authors",
                resolve: context =>
            {
                return(authorData.authors);
                //var authors = db.Authors.Include(a => a.Books);
                //return authors;
            });
        }
 public AuthorMutation(AuthorData authorData)
 {
     Name = "Mutation";
     Field <AuthorType>(
         "createAuthor",
         arguments: new QueryArguments(
             new QueryArgument <NonNullGraphType <AuthorInputType> > {
         Name = "author"
     }
             ),
         resolve: context =>
     {
         var author = context.GetArgument <Author>("author");
         return(authorData.Add(author));
     }
         );
 }
        //private readonly ApplicationDbContext _db;

        //public GraphQLController(ApplicationDbContext db) => _db = db;
        public GraphQLController(AuthorData authorData, ISchema schema)
        {
            this.authorData = authorData;
            this.schema     = schema;
        }