ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.14k stars 736 forks source link

System.NullReferenceException when downloading or initializing #6137

Closed jhueppauff closed 1 year ago

jhueppauff commented 1 year ago

Is there an existing issue for this?

Product

Strawberry Shake

Describe the bug

We are trying to initialize a new project and fetching the schema from an external graphql endpoint.

dotnet graphql init https://some-graphql.endpoint/graphql -n MyProject -p . -x "Authorization=Bearer xyz" -x "OtherHeader=value"

Unfortunately it seems to fail as well if we try just to download the Schema.

Download schema started.
Download schema completed in 1425 ms
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at HotChocolate.Utilities.Introspection.IntrospectionDeserializer.CreateTypeReference(TypeRef typeRef) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionDeserializer.cs:line 354
   at HotChocolate.Utilities.Introspection.IntrospectionDeserializer.CreateTypeReference(TypeRef typeRef) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionDeserializer.cs:line 364
   at HotChocolate.Utilities.Introspection.IntrospectionDeserializer.CreateTypeReference(TypeRef typeRef) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionDeserializer.cs:line 356
   at HotChocolate.Utilities.Introspection.IntrospectionDeserializer.CreateTypeReference(TypeRef typeRef) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionDeserializer.cs:line 364
   at HotChocolate.Utilities.Introspection.IntrospectionDeserializer.CreateTypeReference(TypeRef typeRef) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionDeserializer.cs:line 356
   at HotChocolate.Utilities.Introspection.IntrospectionDeserializer.CreateTypeReference(TypeRef typeRef) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionDeserializer.cs:line 364
   at HotChocolate.Utilities.Introspection.IntrospectionDeserializer.CreateTypeReference(TypeRef typeRef) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionDeserializer.cs:line 356
   at HotChocolate.Utilities.Introspection.IntrospectionDeserializer.CreateFields(IEnumerable`1 fields) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionDeserializer.cs:line 212
   at HotChocolate.Utilities.Introspection.IntrospectionDeserializer.CreateObject(FullType type) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionDeserializer.cs:line 194
   at HotChocolate.Utilities.Introspection.IntrospectionDeserializer.CreateTypes(FullType type) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionDeserializer.cs:line 95
   at HotChocolate.Utilities.Introspection.IntrospectionDeserializer.CreateTypes(ICollection`1 types)+MoveNext() in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionDeserializer.cs:line 77
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
   at HotChocolate.Utilities.Introspection.IntrospectionDeserializer.Deserialize(IntrospectionResult result) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionDeserializer.cs:line 15
   at HotChocolate.Utilities.Introspection.IntrospectionClient.DownloadSchemaAsync(HttpClient client, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionClient.cs:line 78
   at HotChocolate.Utilities.Introspection.IntrospectionClient.DownloadSchemaAsync(HttpClient client, Stream stream, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionClient.cs:line 49
   at StrawberryShake.Tools.DefaultFileSystem.WriteToAsync(String fileName, Func`2 write) in /home/vsts/work/1/s/src/StrawberryShake/Tooling/src/dotnet-graphql/DefaultFileSystem.cs:line 81
   at StrawberryShake.Tools.IntrospectionHelper.DownloadSchemaAsync(HttpClient client, IFileSystem fileSystem, IActivity activity, String fileName, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/StrawberryShake/Tooling/src/dotnet-graphql/IntrospectionHelper.cs:line 21
   at StrawberryShake.Tools.InitCommandHandler.DownloadSchemaAsync(InitCommandContext context, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandHandler.cs:line 110
   at StrawberryShake.Tools.InitCommandHandler.ExecuteInternalAsync(InitCommandContext context, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandHandler.cs:line 87
   at StrawberryShake.Tools.InitCommandHandler.ExecuteAsync(InitCommandArguments arguments, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandHandler.cs:line 73
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at StrawberryShake.Tools.Program.<Main>(String[] args)

We tried other Tools like Apollo to fetch the GraphQL Schema which works, but when we try to import from this file we get an error while building. But that might be due to different Schemas between Apollo and Strawberry?

Determining projects to restore...
  All projects are up-to-date for restore.
  Generate C# Clients started.
  Generate CMSClient started.
  Generate CMSClient completed in 317 ms
  Generate C# Clients completed in 466 ms
  Unhandled exception. System.AggregateException: One or more errors occurred. (The type structure is invalid.)
   ---> System.ArgumentException: The type structure is invalid.
     at HotChocolate.Types.TypeExtensions.NamedType(IType type) in /home/vsts/work/1/s/src/HotChocolate/Core/src/Types/Types/Extensions/TypeExtensions.c 
  s:line 297
     at HotChocolate.Configuration.Validation.InterfaceHasAtLeastOneImplementationRule.Validate(ReadOnlySpan`1 typeSystemObjects, IReadOnlySchemaOptions 
   options, ICollection`1 errors) in /home/vsts/work/1/s/src/HotChocolate/Core/src/Types/Configuration/Validation/InterfaceHasAtLeastOneImplementationRu 
  le.cs:line 52
     at HotChocolate.Configuration.Validation.SchemaValidator.Validate(IEnumerable`1 typeSystemObjects, IReadOnlySchemaOptions options) in /home/vsts/wo 
  rk/1/s/src/HotChocolate/Core/src/Types/Configuration/Validation/SchemaValidator.cs:line 38
     at HotChocolate.Configuration.TypeInitializer.Initialize() in /home/vsts/work/1/s/src/HotChocolate/Core/src/Types/Configuration/TypeInitializer.cs: 
  line 108
     at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, IDescriptorContext context, IReadOnlyList`1 types) in /home/vsts/work/1/ 
  s/src/HotChocolate/Core/src/Types/SchemaBuilder.Setup.cs:line 198
     at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder, LazySchema lazySchema, IDescriptorContext context) in /home/vsts/work/1/s/src/Hot 
  Chocolate/Core/src/Types/SchemaBuilder.Setup.cs:line 63
     at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder) in /home/vsts/work/1/s/src/HotChocolate/Core/src/Types/SchemaBuilder.Setup.cs:lin 
  e 28
     at HotChocolate.SchemaBuilder.Create() in /home/vsts/work/1/s/src/HotChocolate/Core/src/Types/SchemaBuilder.Create.cs:line 10
     at HotChocolate.SchemaBuilder.HotChocolate.ISchemaBuilder.Create() in /home/vsts/work/1/s/src/HotChocolate/Core/src/Types/SchemaBuilder.Create.cs:l 
  ine 29
     at StrawberryShake.CodeGeneration.Utilities.SchemaHelper.Load(IReadOnlyCollection`1 schemaFiles, Boolean strictValidation, Boolean noStore) in /hom 
  e/vsts/work/1/s/src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/SchemaHelper.cs:line 88
     at StrawberryShake.CodeGeneration.CSharp.CSharpGenerator.TryCreateSchema(IReadOnlyList`1 files, Dictionary`2 fileLookup, ICollection`1 errors, Bool 
  ean strictValidation, Boolean noStore, ISchema& schema) in /home/vsts/work/1/s/src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp/CSharpGene 
  rator.cs:line 423
     at StrawberryShake.CodeGeneration.CSharp.CSharpGenerator.GenerateAsync(IEnumerable`1 fileNames, CSharpGeneratorSettings settings) in /home/vsts/wor 
  k/1/s/src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp/CSharpGenerator.cs:line 101
     --- End of inner exception stack trace ---
     at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
     at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
     at StrawberryShake.Tools.GenerateCommand.GenerateCommandHandler.GenerateClient(String clientName, String[] documents, CSharpGeneratorSettings setti 
  ngs) in /home/vsts/work/1/s/src/StrawberryShake/Tooling/src/dotnet-graphql/GenerateCommand.cs:line 164
     at StrawberryShake.Tools.GenerateCommand.GenerateCommandHandler.ExecuteAsync(GenerateCommandArguments args, CancellationToken cancellationToken) in 
   /home/vsts/work/1/s/src/StrawberryShake/Tooling/src/dotnet-graphql/GenerateCommand.cs:line 124
     at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
     at StrawberryShake.Tools.Program.<Main>(String[] args)

Any Idea how to solve this?

Steps to reproduce

  1. dotnet graphql init
  2. dotnet build

Relevant log output

No response

Additional Context?

No response

Version

13.0.5

michaelstaib commented 1 year ago

Can you attach the schema?

michaelstaib commented 1 year ago

You can also send us the schema in a private message on slack.chillicream.com

jhueppauff commented 1 year ago

I need to clarify this. I know this makes it harder to diagnose. But it is an internal API and I am not sure if I am actually allowed to do this.

michaelstaib commented 1 year ago

Does your schema has a type with more than 2 list levels ... like [[[Foo]]]?

michaelstaib commented 1 year ago

The validation check that throws detected a level of type depth greater than six which indicates that there must be a list structure deeper than three. Is this the case? We have limited list nesting to two levels as the spec only defines things to that level. It is not forbidden to have deeper nesting but what is the use-case for this and how deep is the nesting.

jhueppauff commented 1 year ago

Yes, it seems so. I tried to remove those and it seems that those issues are gone now. I will check if I need those types at all . Will do more tests on Monday Thank you so far :)

michaelstaib commented 1 year ago

How many levels of list does your schema have? We could increase it if there is a use-case for it that makes sense.