Describe the bug
I am new to graphql and hot chocolate. Trying to do a simple implementation with graphql and hot chocolate however keep getting the following error:
Unhandled exception. HotChocolate.SchemaException: The type 'System.Int32&' may not be used as a type argument.
at HotChocolate.Configuration.TypeInitializer.Initialize(Func1 schemaResolver, IReadOnlySchemaOptions options)
at HotChocolate.SchemaBuilder.Create()
at HotChocolate.SchemaBuilder.HotChocolate.ISchemaBuilder.Create()
at ClimbStrava.GraphqlApi.Startup.ConfigureServices(IServiceCollection services) in /Users/tonyma/Desktop/ClimbStrava/ClimbStrava.GraphqlApi/Startup.cs:line 44
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.
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()`
Details
Project file:
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.0.2" />
<PackageReference Include="HotChocolate.AspNetCore" Version="10.5.3" />
<PackageReference Include="HotChocolate.AspNetCore.Playground" Version="10.5.3" />
<PackageReference Include="HotChocolate.AspNetCore.Voyager" Version="10.5.3" />
<PackageReference Include="HotChocolate.Subscriptions.InMemory" Version="10.5.3" />
<PackageReference Include="HotChocolate.Subscriptions.Redis" Version="10.5.3" />
<PackageReference Include="HotChocolate.Types.Filters" Version="10.5.3" />
<PackageReference Include="HotChocolate.Types.Selections" Version="10.5.3" />
<PackageReference Include="HotChocolate.Types.Sorting" Version="10.5.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0-rc.2.20475.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="5.0.0-rc.2.20475.6" />
<PackageReference Include="Microsoft.Identity.Web" Version="1.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
ConfigureServices in Startup.cs:
services.AddGraphQL(
SchemaBuilder.New()
.AddQueryType<Query>()
.Create(),
new QueryExecutionOptions { ForceSerialExecution = true });
Configure in StartUp.cs
app.UseGraphQL()
.UsePlayground()
.UseVoyager();
Query type:
public class Query
{
/// <summary>
/// Gets all users.
/// </summary>
public User GetUsers([Service] ClimbStravaDbContext climbStravaDbContext)
{
var a = climbStravaDbContext.Users.FirstOrDefault();
return a;
}
}
Not sure what I did wrong. Are you able to guide me through?
The project worked if I change the query to return a string text:
public string GetUsers([Service] ClimbStravaDbContext climbStravaDbContext)
{
return "hello world";
}
Just noticed the issue caused the List in the class:
Able to run the project after comment out public ICollection<Post> Posts { get; set; }
How can I do code first to build scheme from entity framework class which contain list?
Entity framework class:
` public class Person
{
public Guid ObjectId { get; set; }
public string UserHandle { get; set; }
public string Email { get; set; }
public string Name { get; set; }
public int NumOfPosts { get; set; }
public ICollection<Post> Posts { get; set; }
public int NumOfFollowers { get; set; }
public int NumOfFollowings { get; set; }
}`
Furthermore discovered, it broke by the datatype "Point" from "NetTopologySuite":
Namespace:
using NetTopologySuite.Geometries;
property:
public Point Location { get; set; }
Nuget package:
https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite
The issue that you have is due to a by ref field which does not translate to GraphQL. If you move to the version 11 previews you will have support for spatial types.
Hi @michaelstaib, Thanks for your reply.
I tried to upgrade to v11 however there are quite a bit changes. I am having difficulties to implement v11 as I couldn't find enough document. I probably will continue using v10 and migrate to v11 later once there are more samples and documents available. Thanks again.
Hi @michaelstaib, the sample workshop code is very useful. Many thanks!
@michaelstaib this are my error list in v11
1. Unable to infer or resolve a schema type from the type reference `Input: ICollection`. (HotChocolate.Types.InputObjectType<System.Xml.Schema.XmlSchemaObjectTable>)
2. Unable to infer or resolve a schema type from the type reference `Input: XmlNodeList`. (HotChocolate.Types.InputObjectType<System.Xml.XmlAttribute>)
3. Unable to infer or resolve a schema type from the type reference `Input: Char`.
4. Unable to infer or resolve a schema type from the type reference `Input: IXmlSchemaInfo`. (HotChocolate.Types.InputObjectType<System.Xml.XmlAttribute>)
5. Unable to infer or resolve a schema type from the type reference `Output: DictionaryEntry`.
6. Unable to infer or resolve a schema type from the type reference `Input: Type`.
7. Unable to infer or resolve a schema type from the type reference `Output: Char`.
8. Unable to infer or resolve a schema type from the type reference `Output: RuntimeTypeHandle`.
9. Unable to infer or resolve a schema type from the type reference `Input: Geometry`. (HotChocolate.Types.ObjectType<NetTopologySuite.Geometries.GeometryFactory>)
10. Unable to infer or resolve a schema type from the type reference `Input: Span<Char!>`.
11. Unable to infer or resolve a schema type from the type reference `Input: Int32&`. (HotChocolate.Types.ObjectType<NetTopologySuite.Geometries.CoordinateSequence>)
12. Unable to infer or resolve a schema type from the type reference `Output: RuntimeFieldHandle`.
13. Unable to infer or resolve a schema type from the type reference `Output: InterfaceMapping`.
14. Unable to infer or resolve a schema type from the type reference `Input: XPathExpression`. (HotChocolate.Types.ObjectType<System.Xml.XPath.XPathNavigator>)
15. Unable to infer or resolve a schema type from the type reference `Output: CustomAttributeNamedArgument`.
16. Unable to infer or resolve a schema type from the type reference `Output: CustomAttributeTypedArgument`.
17. Unable to infer or resolve a schema type from the type reference `Output: ModuleHandle`.
18. Unable to infer or resolve a schema type from the type reference `Output: RuntimeMethodHandle`.
19. Unable to infer or resolve a schema type from the type reference `Input: IAsyncResult`.
20. Unable to infer or resolve a schema type from the type reference `Output: IntPtr`.
21. Unable to infer or resolve a schema type from the type reference `Input: Calendar`.
22. Unable to infer or resolve a schema type from the type reference `Input: XmlReader`. (HotChocolate.Types.ObjectType<System.Xml.XmlDocument>)
23. Unable to infer or resolve a schema type from the type reference `Input: MethodInfo`.
24. Unable to infer or resolve a schema type from the type reference `Input: Byte*`.
25. Unable to infer or resolve a schema type from the type reference `Input: XmlSchemaObject`. (HotChocolate.Types.InputObjectType<System.Xml.Schema.XmlSchema>)
26. Unable to infer or resolve a schema type from the type reference `Input: XmlNameTable`. (HotChocolate.Types.InputObjectType<System.Xml.XmlDocument>)
27. Unable to infer or resolve a schema type from the type reference `Input: XmlNode`. (HotChocolate.Types.ObjectType<System.Xml.XmlAttributeCollection>)