GraphQL dotnet上载文件突变而无需使用中继

时间:2019-04-26 09:20:53

标签: graphql graphql-dotnet

我想上传突变版本的文件,我不仅仅使用中继来纯Graphql dotnet

在这里您可以看到我的启动类多么简单

public class Startup
{
    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    { 
        //Registering types and services
        services.AddSingleton<ICategoryService, CategoryService>();
        services.AddSingleton<CategoryType>();

        services.AddSingleton<IProductService, ProductService>();
        services.AddSingleton<ProductType>();
        services.AddSingleton<ProductInputType>();
        services.AddSingleton<Mutations>();

        services.AddSingleton<Queries>();
        services.AddSingleton<MainSchema>();
        //registering GraphQL dependency resolver
        services.AddSingleton<IDependencyResolver>(
            c => new FuncDependencyResolver(type => c.GetRequiredService(type)));


        services.AddGraphQL(options =>
        {
            options.EnableMetrics = true;
            options.ExposeExceptions = true;
        })
          .AddWebSockets() // Add required services for web socket support
          .AddDataLoader(); // Add required services for DataLoader support
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        app.UseDefaultFiles();
        app.UseStaticFiles();

        app.UseWebSockets();

        // use graphiQL middleware at default url /graphiql

        app.UseGraphQLWebSockets<MainSchema>("/graphql");
        app.UseGraphQL<MainSchema>();
    }
}

到目前为止,我对突变的唯一想法是使用base64作为附件的数据类型,我知道这不是最佳解决方案。

我在所有地方都看到了相同的问题,但对于使用中继的人来说,在我看来,我是graphql的新手,所以我正在寻找最简单的方法

这是我的输入图类型

  public class ProductInputType : InputObjectGraphType
{
    public ProductInputType()
    {
        Name = "ProductInput";

        Field<NonNullGraphType<StringGraphType>>("Code");
        Field<NonNullGraphType<StringGraphType>>("Name");
        Field<NonNullGraphType<StringGraphType>>("Description");
        //I want to use this field for the image 
        Field<NonNullGraphType<GraphQL.Types.StringGraphType>>("Image");

    }
}

0 个答案:

没有答案