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.26k stars 745 forks source link

Unable to stitch remote schema with custom scalar type #6269

Closed SARAVANA1501 closed 1 year ago

SARAVANA1501 commented 1 year ago

Is there an existing issue for this?

Product

Hot Chocolate

Describe the bug

We have existing graphql server which is having custom scalar type

public class JObjectGraphType : ScalarGraphType
{
    public JObjectGraphType() => Name = "JObject";

    public override object Serialize(object value) => ParseValue(value);

    public override object ParseValue(object value)
    {
        var jsonString = JsonConvert.SerializeObject(value);
        return JObject.Parse(jsonString);
    }

    public override object ParseLiteral(IValue value) => Serialize(value.Value);
}

Added remote schema

builder.Services.AddHttpClient(APP1, c => c.BaseAddress = new Uri("https://xxx.com/graphql"));
builder.Services.AddHttpClient(APP2, c => { c.BaseAddress = new Uri("http://yyy.com/graphql"); });
builder.Services.AddGraphQLServer().AddRemoteSchema(APP1).AddRemoteSchema(APP2)

Getting below error message

 1. Unable to resolve type reference `[JObject]`. (HotChocolate.Types.ObjectType)

         at HotChocolate.Configuration.RegisteredType.GetType[T](TypeReference typeRef)
         at HotChocolate.Types.OutputFieldBase`1.OnCompleteField(ITypeCompletionContext context, ITypeSystemMember declaringMember, TDefinition definition)
         at HotChocolate.Types.ObjectField.OnCompleteField(ITypeCompletionContext context, ITypeSystemMember declaringMember, ObjectFieldDefinition definition)
         at HotChocolate.Types.FieldBase`1.CompleteField(ITypeCompletionContext context, ITypeSystemMember declaringMember)
         at HotChocolate.Types.FieldBase`1.HotChocolate.Types.Helpers.IFieldCompletion.CompleteField(ITypeCompletionContext context, ITypeSystemMember declaringMember)
         at HotChocolate.Internal.FieldInitHelper.CompleteFieldsInternal[TField](ITypeCompletionContext context, ITypeSystemMember declaringMember, TField[] fields)
         at HotChocolate.Internal.FieldInitHelper.CompleteFieldsInternal[TFieldDefinition,TField](ITypeCompletionContext context, ITypeSystemMember declaringMember, IEnumerable`1 fieldDefinitions, Func`3 fieldFactory, Int32 fieldCount)
         at HotChocolate.Internal.FieldInitHelper.CompleteFields[TFieldDefinition,TField](ITypeCompletionContext context, ITypeSystemMember declaringMember, IReadOnlyList`1 fieldDefs, Func`3 fieldFactory)
         at HotChocolate.Types.ObjectType.OnCompleteFields(ITypeCompletionContext context, ObjectTypeDefinition definition)
         at HotChocolate.Types.ObjectType.OnCompleteType(ITypeCompletionContext context, ObjectTypeDefinition definition)
         at HotChocolate.Types.TypeSystemObjectBase`1.CompleteType(ITypeCompletionContext context)
         at HotChocolate.Configuration.TypeInitializer.CompleteType(RegisteredType registeredType)
         at HotChocolate.Configuration.TypeInitializer.<CompleteTypes>b__29_0(RegisteredType type)
         at HotChocolate.Configuration.TypeInitializer.ProcessTypes(TypeDependencyFulfilled fulfilled, Func`2 action)
         at HotChocolate.Configuration.TypeInitializer.CompleteTypes()
         at HotChocolate.Configuration.TypeInitializer.Initialize()
         at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, IDescriptorContext context, IReadOnlyList`1 types)
         at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder, LazySchema lazySchema, IDescriptorContext context)
         at HotChocolate.SchemaBuilder.Create(IDescriptorContext context)
         at HotChocolate.SchemaBuilder.HotChocolate.ISchemaBuilder.Create(IDescriptorContext context)
         at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaAsync(String schemaName, RequestExecutorSetup options, RequestExecutorOptions executorOptions, IServiceProvider serviceProvider, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)
         at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaServicesAsync(String schemaName, RequestExecutorSetup options, CancellationToken cancellationToken)
         at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorNoLockAsync(String schemaName, CancellationToken cancellationToken)
         at Microsoft.Extensions.DependencyInjection.HotChocolateStitchingRequestExecutorExtensions.<>c__DisplayClass5_0.<<AddRemoteSchema>b__2>d.MoveNext()
      --- End of stack trace from previous location ---
         at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaAsync(String schemaName, RequestExecutorSetup options, RequestExecutorOptions executorOptions, IServiceProvider serviceProvider, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)
         at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaServicesAsync(String schemaName, RequestExecutorSetup options, CancellationToken cancellationToken)
         at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorNoLockAsync(String schemaName, CancellationToken cancellationToken)
         at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorAsync(String schemaName, CancellationToken cancellationToken)
         at HotChocolate.Execution.RequestExecutorProxy.GetRequestExecutorAsync(CancellationToken cancellationToken)
         at HotChocolate.AspNetCore.HttpPostMiddlewareBase.HandleRequestAsync(HttpContext context)
         at HotChocolate.AspNetCore.HttpPostMiddlewareBase.InvokeAsync(HttpContext context)
         at Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions.<>c__DisplayClass20_0.<<UseCancellation>b__1>d.MoveNext()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Can you explain how to solve this issue?

Steps to reproduce

  1. Create graphql server with
  2. Add custom type given above.
  3. Create stitching server with hot chocolate
  4. Add remote schema
  5. Try to access the schema of stitching server

Relevant log output

No response

Additional Context?

No response

Version

13.0.5

michaelstaib commented 1 year ago

Stitching is end of life. You can migrate you project to HotChocolate.Fusion which has out of the box support for json scalars.

SARAVANA1501 commented 1 year ago

hi @michaelstaib You mean combining two or three graphql servers is not possible in hot chocolate?

michaelstaib commented 1 year ago

No,

HotChocolate.Stitching is replaced by HotChocolate.Fusion. You are using the old library. https://www.youtube.com/watch?v=peMdejyrKD4

SARAVANA1501 commented 1 year ago
image

While running Getting the same error. After removing all the reference to JObject it is working fine. so seems like some configuration needed in the gateway or gateway graph creation

SARAVANA1501 commented 1 year ago

@michaelstaib Any update on this

michaelstaib commented 1 year ago

Create a new issue with a Repro for fusion.