I just tried to get a working sample in my .net core rest api with this project, as this looks like exactly the thing that I need. So I have this code in my controller (The context is injected):
`[HttpGet()]
public async Task GetUsers()
{
var schema = GraphQL.CreateDefaultSchema(() => _context);
var user = schema.AddType<User>();
user.AddField(u => u.Id);
user.AddField(u => u.Name);
user.AddField(u => u.Age);
schema.AddListField("users", db => db.Users);
schema.Complete();
var query = @"{
users {
Id
Name
}}";
var gql = new GraphQL<EventStoreContext>(schema);
var dict = gql.ExecuteQuery(query);
var serializeObject = JsonConvert.SerializeObject(dict, Formatting.Indented);
Console.WriteLine(serializeObject);
return new OkObjectResult(serializeObject);
}`
but on execution, i get a System.TypeInitializationException from GraphQL.Net.DynamicTypeBuilder
Connection id "0HLCNLH1V91BN", Request id "0HLCNLH1V91BN:00000001": An unhandled exception was thrown by the application. System.TypeInitializationException: The type initializer for 'GraphQL.Net.DynamicTypeBuilder' threw an exception. ---> System.MissingMethodException: Method not found: 'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'. at GraphQL.Net.DynamicTypeBuilder..cctor() --- End of inner exception stack trace --- at GraphQL.Net.DynamicTypeBuilder.CreateDynamicType(String name, Dictionary2 properties)
at GraphQL.Net.GraphQLSchema1.CompleteType(GraphQLType type) at GraphQL.Net.GraphQLSchema1.CompleteTypes(IEnumerable1 types) at GraphQL.Net.GraphQLSchema1.Complete()
at HttpAdapter.Users.UserGraphlController.d6.MoveNext() in C:\Users\Simon\source\repos\MicrowaveWebService\GraphlAdapter\UserGraphlController.g.cs:line 49
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.d4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.d3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.d2.MoveNext()
`
I just tried to get a working sample in my .net core rest api with this project, as this looks like exactly the thing that I need. So I have this code in my controller (The context is injected):
`[HttpGet()] public async Task GetUsers()
{
var schema = GraphQL.CreateDefaultSchema(() => _context);
but on execution, i get a
System.TypeInitializationException
fromGraphQL.Net.DynamicTypeBuilder
Connection id "0HLCNLH1V91BN", Request id "0HLCNLH1V91BN:00000001": An unhandled exception was thrown by the application. System.TypeInitializationException: The type initializer for 'GraphQL.Net.DynamicTypeBuilder' threw an exception. ---> System.MissingMethodException: Method not found: 'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'. at GraphQL.Net.DynamicTypeBuilder..cctor() --- End of inner exception stack trace --- at GraphQL.Net.DynamicTypeBuilder.CreateDynamicType(String name, Dictionary
2 properties) at GraphQL.Net.GraphQLSchema1.CompleteType(GraphQLType type) at GraphQL.Net.GraphQLSchema
1.CompleteTypes(IEnumerable1 types) at GraphQL.Net.GraphQLSchema
1.Complete() at HttpAdapter.Users.UserGraphlController.Am I missing something here?