graphql-dotnet / relay

A toolset for creating Relay.js compatible GraphQL servers in dotnet.
MIT License
75 stars 29 forks source link

Dependency Injection #4

Open rsbst23 opened 7 years ago

rsbst23 commented 7 years ago

I am having a hard time figuring out how you get StarWarsData into the DroidType class.

public class Droid { public string DroidId { get; set; } public string Name { get; set; } }

public class DroidType : NodeGraphType { public DroidType() { Name = "Droid";

Id(d => d.DroidId); // adds an id Field as well as the `Droid` id field

Field<StringGraphType>("name", "The name of the droid.");

}

public override Droid GetById(string droidId) { return StarWarsData.GetDroidByIdAsync(droidId); } }

I started my project by following the pattern that Jacek Kosciesza did in his StarWars example [https://github.com/JacekKosciesza/StarWars] and I was able to get dependency injection to work in my ModelType (i.e. DroidType classes).

However, I am trying to get my project to work with React / Relay, so I wanted to change my server to follow that specification. I found your library and started to refactor things. When I changed my RootQuery to inherit from QueryGraphType, I receive the error:

"Cannot return null for non-null type. Field: type, Type: __Type!."

"stackTrace": " at GraphQL.DocumentExecuter.d14.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at GraphQL.DocumentExecuter.d12.MoveNext()",

I'm hoping you have some ideas on how I can get past this.

thomasbrueggemann commented 5 years ago

@rsbst23 How did you get DI to work with the NodeGraphType class, here DroidType. As soon as I pass in dependencies via constructor injection the GraphQL.NET library stops using these types for the schema. Did you you property-injection?

It's been two years since you opened the issue, but maybe you still remember :-)