Coder Social home page Coder Social logo

shane32 / graphql-dotnet-upload Goto Github PK

View Code? Open in Web Editor NEW

This project forked from janniklassahn/graphql-dotnet-upload

0.0 0.0 0.0 61 KB

Experimental middleware and an Upload scalar to add support for GraphQL multipart requests for ASP.NET Core

License: MIT License

C# 100.00%

graphql-dotnet-upload's Introduction

graphql-dotnet-upload

Build Status NuGet

This repository contains an experimental implementation of the GraphQL multipart request spec based on ASP.NET Core.

Installation

You can install the latest version via NuGet.

PM> Install-Package GraphQL.Upload.AspNetCore

Preview versions from the develop branch are available via GitHub Packages.

Usage

Register the middleware in your Startup.cs.

This middleware implementation only parses multipart requests. That's why we're using additional middleware (graphql-dotnet/server) to handle other request types.

public void ConfigureServices(IServiceCollection services)
{
  services.AddSingleton<MySchema>()
          .AddGraphQLUpload()
          .AddGraphQL();
}

public void Configure(IApplicationBuilder app)
{
  app.UseGraphQLUpload<MySchema>()
     .UseGraphQL<MySchema>();
}

Use the upload scalar in your resolvers. Files are exposed as IFormFile.

Field<StringGraphType>(
    "singleUpload",
    arguments: new QueryArguments(
        new QueryArgument<UploadGraphType> { Name = "file" }),
    resolve: context =>
    {
        var file = context.GetArgument<IFormFile>("file");
        return file.FileName;
    });

Testing

Take a look at the tests and the sample and run some of the cURL requests the spec lists if you are curious.

CMD:

curl localhost:54234/graphql ^
	-F operations="{ \"query\": \"mutation ($file: Upload!) { singleUpload(file: $file) { name } }\", \"variables\": { \"file\": null } }" ^
	-F map="{ \"0\": [\"variables.file\"] }" ^
	-F [email protected]

Bash:

curl localhost:54234/graphql \
	-F operations='{ "query": "mutation ($file: Upload!) { singleUpload(file: $file) { name } }", "variables": { "file": null } }' \
	-F map='{ "0": ["variables.file"] }' \
	-F [email protected]

graphql-dotnet-upload's People

Contributors

janniklassahn avatar ganhammar avatar ruseinov avatar lydonchandra avatar scrodde avatar stefangies99 avatar tobias-tengler avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.