Error deleting an entity after adding it
Current build does not allow you to create an entity and then with another mutation delete that entity.
Steps to reproduce:
- Create Add Mutation
- Create Delete Mutation
- Add item
mutation ($day: DayInput!) {
createDay(day:$day){
id
agendaDay
}
}
mutation ($day: DayInput!) {
createDay(day:$day){
id
agendaDay
}
}
- Immediately try and delete
mutation ($dayId: Int!) {
deleteDay(dayId:$dayId){
id
agendaDay
}
}
{
"dayId" : "7004"
}
I get the following error
{
"data": {
"deleteDay": null
},
"errors": [
{
"message": "There was an error deleting 7004: The instance of entity type 'Day' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"deleteDay"
]
}
]
}
I believe this line is the reason
var sp = services.BuildServiceProvider();
services.AddSingleton<ISchema>(new MITSSchema(new FuncDependencyResolver(type =>sp.GetService(type))));
I replaced it with below and it works as expected.
services.AddScoped<IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService));
services.AddScoped<IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService));
this generated errors on graphiql for me
Hi @omar84 - do you see the same error @jcsilvers reported? I fixed an issue a couple of weeks ago with the scoping of the repository dependencies that I believe were the root cause of @jcsilvers issue but if you're still seeing it perhaps there is still something lingering.
@mmacneil I didn't try his scenario to be honest, I just thought, if there is an issue, I would want to fix it :)
if you believe its already fixed, then this should probably be closed
ok thanks..so do you get an error (in any scenario) in graphiql?
On Mon, Apr 1, 2019, 5:37 PM Omar M., [email protected] wrote:
@mmacneil https://github.com/mmacneil I didn't try his scenario to be honest, I just thought, if there is an issue, I would want to fix it :)
if you believe its already fixed, then this should probably be closed
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mmacneil/ASPNetCoreGraphQL/issues/2#issuecomment-478737890, or mute the thread https://github.com/notifications/unsubscribe-auth/AAXRu2bgFRD1AnM4wNTyXnT_D4XnzYxiks5vcm4BgaJpZM4ZLtkR .
not with your code, but with what @jcsilvers suggested