This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); | |
services | |
.AddMvc() | |
.AddJsonOptions( | |
options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore | |
) | |
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataSchema : Schema | |
{ | |
public DataSchema(IDependencyResolver resolver) : base(resolver) | |
{ | |
Query = resolver.Resolve<Query>(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Query : ObjectGraphType | |
{ | |
public Query(Repository repository) | |
{ | |
Field<ListGraphType<PostType>>("posts", | |
arguments: new QueryArguments(new List<QueryArgument> | |
{ | |
new QueryArgument<IdGraphType> | |
{ | |
Name = "id" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Field<ListGraphType<CommentType>, IEnumerable<Comment>>().Name("Comment") | |
.ResolveAsync(ctx => | |
{ | |
return repository.GetCommentByPostId(ctx.Source.Id); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PostType : ObjectGraphType<Post> | |
{ | |
public PostType(Repository repository) | |
{ | |
Field(x => x.Id); | |
Field(x => x.Title); | |
Field(x => x.Body); | |
Field(x => x.UserId); | |
Field<ListGraphType<CommentType>, IEnumerable<Comment>>().Name("Comment") | |
.ResolveAsync(ctx => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<PackageReference Include="GraphQL" Version="2.4.0" /> | |
<PackageReference Include="GraphQL.Server.Transports.AspNetCore" Version="3.4.0" /> | |
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="3.4.0" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddDbContext<AppDbContext>(options => | |
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection") | |
); | |
services | |
.AddMvc() | |
.AddJsonOptions( | |
options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Repository | |
{ | |
private readonly AppDbContext _appDbContext; | |
public Repository(AppDbContext appDbContext) | |
{ | |
_appDbContext = appDbContext; | |
} | |
public IQueryable<Post> GetPostQuery() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddDbContext<AppDbContext>(options => | |
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection") | |
); | |
services | |
.AddMvc() | |
.AddJsonOptions( | |
options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Post | |
{ | |
public int UserId { get; set; } | |
[DatabaseGenerated(DatabaseGeneratedOption.None)] | |
public int Id { get; set; } | |
public string Title { get; set; } | |
public string Body { get; set; } | |
public ICollection<Comment> Comments { get; set; } | |
} |