Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

.net core - Hotchocolate - Specified method is not supported

I'm trying to implement Hotchocolate on multi-layered APIs like the following

A -> B -> C, D, E, ...

Here is my request :

{
    objectC(id: 111){
        fieldA
        fieldB
    }
}

If I execute this from B, it works perfectly, I can re-execute it without any error.

When I execute this same request from A, it works on the first call but the next ones (same request body) will return "Specified method is not supported" each time while I don't restart B service. If I add a new field in the request, it does the same, works on first execution and errors on the next ones.

C, D, E, .. defines EntityFramework implementation of Hotchocolate GraphQL withtout any extension. It implements Dataloaders :

private void ConfigureServicesGraphQL(IServiceCollection services)
{
    services
        .AddGraphQLServer()
            .AddQueryType(d => d.Name("Query"))
                .AddType<ObjectCQuery>()
                .AddType<ObjectCType>()
                .AddDataLoader<ObjectCByIdDataLoader>()
            .EnableRelaySupport()
            .AddFiltering()
            .AddSorting();
}

B implements stitching schema of C, D, E and the others and extend types to add business value :

private void ConfigureServicesGraphQL(IServiceCollection services)
{
    // Clients
    services.AddHttpClient("ObjectC", (sp, client) => { client.BaseAddress = new Uri(Configuration.GetValue<string>("urls:ObjectC") + "/v1/graphql"); });
    services.AddHttpClient("ObjectD", (sp, client) => { client.BaseAddress = new Uri(Configuration.GetValue<string>("urls:ObjectD") + "/v1/graphql"); });
    services.AddHttpClient("ObjectE", (sp, client) => { client.BaseAddress = new Uri(Configuration.GetValue<string>("urls:ObjectE") + "/v1/graphql"); });

    services
        .AddGraphQLServer()
            // Remote Schemas
            .AddRemoteSchema("ObjectC", false)
            .AddRemoteSchema("ObjectD", false)
            .AddRemoteSchema("ObjectE", false)
            // Extensions
            .AddTypeExtensionsFromFile("ObjectCExtensions.graphql")
            .AddTypeExtensionsFromFile("ObjectDExtensions.graphql")
            .AddTypeExtensionsFromFile("ObjectEExtensions.graphql")
            // Options
            .AddErrorFilter<GraphQLErrorFilter>();
}

A implements stitching schema of B and extend types to add new business value :

private void ConfigureServicesGraphQL(IServiceCollection services)
{
    // Clients
    services.AddHttpClient("ObjectB", (sp, client) => { client.BaseAddress = new Uri(Configuration.GetValue<string>("urls:ObjectB") + "/v1/graphql"); });

    services.AddGraphQLServer()
        // Merge Directive Rule to manage multi layered stitching
        .AddDirectiveMergeRule(next => (c, d) =>
        {
            List<IDirectiveTypeInfo> newDirectives = new List<IDirectiveTypeInfo>();
            List<IDirectiveTypeInfo> returnedValue = (List<IDirectiveTypeInfo>)d;
            List<string> dirToRemove = new List<string>()
            {
                "delegate",
                "cost",
                "computed",
                "source"
            };
            foreach (var dti in returnedValue)
            {
                ISchemaInfo si = dti.Schema;
                foreach (var dir in dirToRemove)
                    ((Dictionary<string, DirectiveDefinitionNode>)si.Directives).Remove(dir);
                if (!dirToRemove.Contains(dti.Definition.Name.Value))
                    newDirectives.Add(new DirectiveTypeInfo(dti.Definition, si));
            }

            next(c, newDirectives);
        })
        .AddRemoteSchema("ObjectB")
        .AddTypeExtensionsFromFile("Extensions.graphql")
        .AddErrorFilter<GraphQLErrorFilter>()
}

I don't understand why the same request does not work twice.. I presume some cache on "B", i tried a lot of configurations (requests options, tracing preferences, strict validation ...) but same result.

Help please ! :)

question from:https://stackoverflow.com/questions/65881989/hotchocolate-specified-method-is-not-supported

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...