如何调用hotchocaly azure函数隔离/程序外的hotchocaly的useendpoints()和mapgraphql()?

发布于 2025-01-24 18:11:39 字数 1132 浏览 0 评论 0原文

我关注此仓库 https://github.com/chandsalam1108/graphqlazfunctionnet5/grazfunctionnet5 ://chillicream.com/docs/hotchocaly/server/endpoints#mapgraphql“ rel =” nofollow noreferrer“> https://chillicream.com/docs/docs/hotchocaly/hotchocaly/server/server/server/server/server/endentpoints#mapgraphpoints#mapgraphql

代码> mapgraphql()?我只能访问iHost


    public class Program
    {
        public static void Main()
        {
            var host = new HostBuilder()
                .ConfigureFunctionsWorkerDefaults()
                .ConfigureServices(s =>
                {
                    s.AddTransient<IUserRepository, UserRepository>();
                    s.AddSingleton<GraphQLAzureFunctionsExecutorProxyV12>();
                    s.AddGraphQLServer()
                    .AddQueryType<Query>()
                    .AddFiltering()
                    .AddSorting();

                }).Build();

            host.Run();
        }
    }

I follow this repo https://github.com/chandsalam1108/GraphQLAzFunctionNet5 and https://chillicream.com/docs/hotchocolate/server/endpoints#mapgraphql

How do I call MapGraphQL()? I only have access to IHost:


    public class Program
    {
        public static void Main()
        {
            var host = new HostBuilder()
                .ConfigureFunctionsWorkerDefaults()
                .ConfigureServices(s =>
                {
                    s.AddTransient<IUserRepository, UserRepository>();
                    s.AddSingleton<GraphQLAzureFunctionsExecutorProxyV12>();
                    s.AddGraphQLServer()
                    .AddQueryType<Query>()
                    .AddFiltering()
                    .AddSorting();

                }).Build();

            host.Run();
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

往日 2025-01-31 18:11:39

作为版本13的Hotchocaly预览,没有模式支持。因此,您可以使用此非常兼容的lib:

dotnet add package Markind.HotChocolate.AzureFunctions.IsolatedProcess

然后像平常一样设置模式名称,就像您在addgraphqlserver(“ schemaname”)中所做的

    using Microsoft.Azure.Functions.Extensions.DependencyInjection;

    var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices(s =>{
        s.AddGraphQLServer("persons") // schema 1
        .AddQueryType<Query>();

        s.AddGraphQLServer("persons2") // schema 2 , etc.
        .AddQueryType<Query2>();
    })
    .AddGraphQLFunctions()// Add support for Azure FunctionS
    .Build();

    host.Run();

一样

    private readonly IMultiSchemaRequestExecutor _executor;

    public GraphQLFunction(IMultiSchemaRequestExecutor executor)
    {
        _executor = executor;
    }

    [Function("GraphQLHttpFunction")]
    public Task<HttpResponseData> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "persons/{**slug}")]
        HttpRequestData request)
        => _executor.ExecuteAsync(request, "persons");

注意最后一行具有schemaname:“人” 。添加另一个功能以使用另一个schemaname。

如果切换到程序内使用Azure函数,则可以使用此

As version 13 preview of HotChocolate there is no support for schemas. So instead you can use this very compatible lib:

dotnet add package Markind.HotChocolate.AzureFunctions.IsolatedProcess

Then setup the schema name as you normally would do in AddGraphQLServer("schemaName"):

    using Microsoft.Azure.Functions.Extensions.DependencyInjection;

    var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices(s =>{
        s.AddGraphQLServer("persons") // schema 1
        .AddQueryType<Query>();

        s.AddGraphQLServer("persons2") // schema 2 , etc.
        .AddQueryType<Query2>();
    })
    .AddGraphQLFunctions()// Add support for Azure FunctionS
    .Build();

    host.Run();

Then in your function use IMultiSchemaRequestExecutor

    private readonly IMultiSchemaRequestExecutor _executor;

    public GraphQLFunction(IMultiSchemaRequestExecutor executor)
    {
        _executor = executor;
    }

    [Function("GraphQLHttpFunction")]
    public Task<HttpResponseData> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "persons/{**slug}")]
        HttpRequestData request)
        => _executor.ExecuteAsync(request, "persons");

Notice last line has the schemaName:"persons". Add another function to use another schemaName.

If you switch to use Azure Function in-process, instead you can use this equivalent.

爱已欠费 2025-01-31 18:11:39

hotchocaly(版本13.0.5)的最新稳定版本盒子支持孤立的过程Azure在.NET 6.0及更高版本中功能。您需要通过从终端运行以下命令来安装其模板的最新版本:

dotnet new -i HotChocolate.Templates::13.0.5 

完成后,您可以使用Hotchocaly GraphQl函数隔离模板创建一个新项目。这将自动引导您的Azure隔离过程功能应用程序使用GraphQl。

查看此视频以获取有关如何执行此操作的更多详细信息:“ nofollow noreferrer”> serverless graphql

The latest stable version of HotChocolate (version 13.0.5) has out of the box support for Isolated Process Azure functions in .Net 6.0 and above. You need to install the latest version of their templates by running the following command from your terminal:

dotnet new -i HotChocolate.Templates::13.0.5 

Once that is done, you can create a new project using the HotChocolate GraphQL Function Isolated template. This will automatically bootstrap your Azure Isolated Process function application to use GraphQL.

Check out this video for more detailed info about how to do this: Serverless GraphQL with Hot Chocolate and Azure Functions

亢潮 2025-01-31 18:11:39

IHOST用于构建无头服务,并用于控制台应用程序。

在端点上使用mapgraphql()时,将有助于获取和发布请求。

IHOST用于创建应用程序将运行的主机。

请参阅此 acrats 史蒂夫·戈登

Ihost is used to build headless services and is used on a console application.

While using MapGraphQL() on an endpoint will help get and post requests.

Ihost is used to create host on which the app will run.

refer this article by STEVE GORDON

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文