graphql-dotnet / graphql-dotnet/conventions

Using user context with GraphQL Server?

Open
#213 0 comments 0 reactions 1 assignee Claimed by @tlil View on GitHub
enhancement
Dominant language
C#
Stars
228
Forks
62
PR merge metrics
No merged PRs in 30d

Description

I was trying out the library and found that there doesn't seem to be a good way to use it with [GraphQL Server](https://github.com/graphql-dotnet/server) and access the user context that that library provides (via [`AddUserContextBuilder`](https://github.com/graphql-dotnet/server/blob/a41d7c318760226af17ed33b9e4ebe8e900032a7/src/Transports.AspNetCore/GraphQLBuilderExtensions.cs)).

This Conventions library seems to only take in the context once you create an executor, but that's handled internally by the Server library. I would expect that the Conventions library would have some way to either mark or recognize a parameter as provided by an internal process like the Server library. Maybe there needs to be an explicit integration package between Conventions and Server.

With [this branch of my project](https://github.com/forte-music/Forte.NET/tree/test/graphql-conventions-context) I get the following error on startup:

Unhandled exception. System.ArgumentOutOfRangeException: A type name can not be null or empty. (Parameter 'name')

at GraphQL.Utilities.NameValidator.ValidateNameNotNull(String name, String type) in /_/src/GraphQL/Utilities/NameValidator.cs:line 31
at GraphQL.Utilities.NameValidator.ValidateName(String name, String type) in /_/src/GraphQL/Utilities/NameValidator.cs:line 13
at GraphQL.Types.GraphType.SetName(String name, Boolean validate) in /_/src/GraphQL/Types/GraphType.cs:line 49
at GraphQL.Types.GraphType.set_Name(String value) in /_/src/GraphQL/Types/GraphType.cs:line 65
at GraphQL.Conventions.Adapters.GraphTypeAdapter.ConstructType[TReturnType](Type template, GraphTypeInfo typeInfo)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.ConstructInputType(GraphTypeInfo typeInfo)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.GetComplexType(GraphTypeInfo typeInfo)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.DeriveType(GraphTypeInfo typeInfo)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.GetType(GraphTypeInfo typeInfo)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.DeriveField(GraphFieldInfo fieldInfo)
at System.Linq.Enumerable.SelectListIterator`2.MoveNext()
at GraphQL.Conventions.Adapters.GraphTypeAdapter.DeriveFields(GraphTypeInfo typeInfo, IComplexGraphType graphType)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.ConstructInterfaceType(GraphTypeInfo typeInfo)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.GetComplexType(GraphTypeInfo typeInfo)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.DeriveType(GraphTypeInfo typeInfo)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.GetType(GraphTypeInfo typeInfo)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.DeriveArgument(GraphArgumentInfo argumentInfo)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at GraphQL.Types.QueryArguments..ctor(IEnumerable`1 list) in /_/src/GraphQL/Types/QueryArguments.cs:line 20
at GraphQL.Conventions.Adapters.GraphTypeAdapter.DeriveField(GraphFieldInfo fieldInfo)
at System.Linq.Enumerable.SelectListIterator`2.MoveNext()
at GraphQL.Conventions.Adapters.GraphTypeAdapter.DeriveFields(GraphTypeInfo typeInfo, IComplexGraphType graphType)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.ConstructOutputType(GraphTypeInfo typeInfo)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.GetComplexType(GraphTypeInfo typeInfo)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.DeriveType(GraphTypeInfo typeInfo)
at GraphQL.Conventions.Adapters.GraphTypeAdapter.DeriveSchema(GraphSchemaInfo schemaInfo)
at GraphQL.Conventions.Builders.SchemaConstructor`2.Build(TypeInfo[] schemaTypes)
at GraphQL.Conventions.Builders.SchemaConstructor`2.Build(Type[] schemaTypes)
at GraphQL.Conventions.GraphQLEngine.BuildSchema(SchemaPrinterOptions options, Type[] types)
at GraphQL.Conventions.GraphQLEngine.BuildSchema(Type[] types)
at Forte.NET.Startup.ConfigureServices(IServiceCollection services) in /home/mark/media/Forte/Forte.NET/Forte.NET/Startup.cs:line 27
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.g__Startup|0(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.b__0(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at Forte.NET.Program.Main(String[] args) in /home/mark/media/Forte/Forte.NET/Forte.NET/Program.cs:line 7

The notable files are [`Startup.cs`], [`Query.cs`], and [`ForteDbContext.cs`].

[`Startup.cs`]: https://github.com/forte-music/Forte.NET/blob/test/graphql-conventions-context/Forte.NET/Startup.cs
[`Query.cs`]: https://github.com/forte-music/Forte.NET/blob/test/graphql-conventions-context/Forte.NET/Schema/Query.cs
[`ForteDbContext.cs`]: https://github.com/forte-music/Forte.NET/blob/test/graphql-conventions-context/Forte.NET/Database/ForteDbContext.cs

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.