Closed hungnguyen2505 closed 5 years ago
Hi, This what we have :
services.AddGraphQL().AddWebSockets().AddDataLoader();
Autofac for DI:
builder.RegisterType<PrincipalListener>().AsImplementedInterfaces();
builder.RegisterType<HttpContextAccessor>().AsImplementedInterfaces();
builder.Register<DocumentWriter>(c => new DocumentWriter(false)).AsImplementedInterfaces().SingleInstance();
builder.RegisterType<DocumentExecuter>().AsImplementedInterfaces().SingleInstance();
builder.Register<GraphQLSchema>(c =>
{
var cc = c.Resolve<IComponentContext>();
var dependencyResolver = new FuncDependencyResolver(type => cc.Resolve(type));
return new GraphQLSchema(dependencyResolver);
}).AsSelf().AsImplementedInterfaces().SingleInstance();
HttpContextAccessor is required in PrincipalListener to assign Context User to WebSockets properties.
Then:
app.UseMiddleware<NtlmAndAnonymousSetupMiddleware>();
app.UseWebSockets();
app.UseGraphQLWebSockets<GraphQLSchema>("/api/graphql");
We have Specific controller named GraphQLController, where all requests are posted instead of using inbuilt middleware.
I remember I had same error as you, but cannot remember what I did to fix it. :-(
Hope this helps.
Had the same problem, earlier I've tried to do
containerBuilder.RegisterType<MachShopSchema>().As<ISchema>().InstancePerRequest();
but specifying it as a singleton with directly provided IDependencyResolver fixed it
containerBuilder.Register(c =>
{
var cc = c.Resolve<IComponentContext>();
var dependencyResolver = new FuncDependencyResolver(type => cc.Resolve(type));
return new MachShopSchema(dependencyResolver);
}).AsSelf().AsImplementedInterfaces().SingleInstance();
Hi everyone,
Currently, I'm good to use GraphQL Dotnet with Query and Mutation without Middleware Build-in.
When trying to use build-in middleware of GraphQLDotnet Server I facing this issue in Autofac:
Or Microsoft dependency
I don't know what I missing to use with the build-in middle ware:
Here is what I registered for GraphQL:
If I do not use the middleware build-in the GraphQL can work for mutation and query but I cannot use subscriptions.
Does anyone have any suggestion what I am missing in the config?
Here is the constructor of the schema query and subscription
Subscription
The reason I am switching to the build-in middle ware to able use the subscription via websockets. Thank u,