Skip to content

Commit c823c0a

Browse files
committed
Register converter in extension methods
1 parent fdc995e commit c823c0a

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff 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
4634
Field<StringGraphType>(
4735
"singleUpload",

src/GraphQL.Upload.AspNetCore/ApplicationBuilderExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

tests/GraphQL.Upload.AspNetCore.Tests/TestSchema.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)