File tree Expand file tree Collapse file tree 3 files changed +8
-15
lines changed
src/GraphQL.Upload.AspNetCore
tests/GraphQL.Upload.AspNetCore.Tests Expand file tree Collapse file tree 3 files changed +8
-15
lines changed Original file line number Diff line number Diff line change @@ -29,19 +29,7 @@ public void Configure(IApplicationBuilder app)
2929}
3030```
3131
32- Register the converter in your schema.
33- ``` csharp
34- public class MySchema : Schema
35- {
36- public MySchema ()
37- {
38- RegisterValueConverter (new FormFileConverter ());
39- // ...
40- }
41- }
42- ```
43-
44- Finally, use the upload scalar in your resolvers. Files are exposed as ` IFormFile ` .
32+ Use the upload scalar in your resolvers. Files are exposed as ` IFormFile ` .
4533``` csharp
4634Field <StringGraphType >(
4735 " singleUpload" ,
Original file line number Diff line number Diff line change @@ -40,6 +40,13 @@ public static IApplicationBuilder UseGraphQLUpload<TSchema>(this IApplicationBui
4040 if ( options is null )
4141 throw new ArgumentNullException ( nameof ( options ) ) ;
4242
43+ var schema = ( TSchema ) builder . ApplicationServices . GetService ( typeof ( TSchema ) ) ;
44+
45+ if ( schema == null )
46+ throw new ArgumentException ( $ "No service type for { typeof ( TSchema ) . FullName } registered.") ;
47+
48+ schema . RegisterValueConverter ( new FormFileConverter ( ) ) ;
49+
4350 return builder . UseWhen ( context => context . Request . Path . StartsWithSegments ( path ) , branch => branch . UseMiddleware < GraphQLUploadMiddleware < ISchema > > ( options ) ) ;
4451 }
4552 }
Original file line number Diff line number Diff line change @@ -9,8 +9,6 @@ public class TestSchema : Schema
99 {
1010 public TestSchema ( )
1111 {
12- RegisterValueConverter ( new FormFileConverter ( ) ) ;
13-
1412 Query = new Query ( ) ;
1513 Mutation = new Mutation ( ) ;
1614 }
You can’t perform that action at this time.
0 commit comments