Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error deleting an entity after adding it #2

Open
jcsilvers opened this issue Dec 10, 2018 · 5 comments
Open

Error deleting an entity after adding it #2

jcsilvers opened this issue Dec 10, 2018 · 5 comments

Comments

@jcsilvers
Copy link

Current build does not allow you to create an entity and then with another mutation delete that entity.

Steps to reproduce:

  1. Create Add Mutation
  2. Create Delete Mutation
  3. Add item
mutation ($day: DayInput!)  {
  createDay(day:$day){
    id
    agendaDay
  }
}

mutation ($day: DayInput!)  {
  createDay(day:$day){
    id
    agendaDay
  }
}

  1. 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));
@omar84
Copy link

omar84 commented Apr 1, 2019

services.AddScoped(s => new FuncDependencyResolver(s.GetRequiredService));

this generated errors on graphiql for me

@mmacneil
Copy link
Owner

mmacneil commented Apr 1, 2019

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.

@omar84
Copy link

omar84 commented Apr 1, 2019

@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

@mmacneil
Copy link
Owner

mmacneil commented Apr 1, 2019 via email

@omar84
Copy link

omar84 commented Apr 1, 2019

not with your code, but with what @jcsilvers suggested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants