C
C#16mo ago
stevie

❔ How to organize folder structure in .NET with HotChocolate 13

Can someone please guide me on organizing folder structure in HotChocolate 13 GraphQL here. We have entities and DbContext. Can I use them instead of creating Types? Also, I've seen many cases where people create folders for each command e.g. /Queries/AddProduct/AddProduct.cs, AddProductInput.cs, AddProductPayload.cs And also seen people creating /Queries/ProductQueries.cs and store all commands init. And store AddProductInput.cs and AddProductPayload.cs in /Models folder. How do I follow Relay pattern and organize with scalability in mind?
3 Replies
stevie
stevieOP16mo ago
Here is what I'm doing:
C# public class AccountMutations
{
public async Task<AddAccountPayload> AddAccountAsync(
AddAccountInput input,
[Service] DataContext context)
{
var account = new Account
{

FirstName = input.FirstName,
SecondName = input.SecondName,
UserId = input.UserId
};

context.Accounts.Add(account);
await context.SaveChangesAsync();
return new AddAccountPayload(account);
}
}
C# public class AccountMutations
{
public async Task<AddAccountPayload> AddAccountAsync(
AddAccountInput input,
[Service] DataContext context)
{
var account = new Account
{

FirstName = input.FirstName,
SecondName = input.SecondName,
UserId = input.UserId
};

context.Accounts.Add(account);
await context.SaveChangesAsync();
return new AddAccountPayload(account);
}
}
Omnissiah
Omnissiah16mo ago
i would keep it to (mostly) one class per file because it's useful for versioning a folder for each command is a lot, i would keep it a little more vertical, so no models folder (at most i would use a models project)
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server