This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
forked from yandooo/graphql-spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #712 from tmkhanh/feature/graphql-test-template-fi…
…le-upload-support Function for GraphQLTestTemplate to upload files using Upload scalar
- Loading branch information
Showing
7 changed files
with
236 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/beans/DummyMutation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.graphql.spring.boot.test.beans; | ||
|
||
import graphql.kickstart.servlet.apollo.ApolloScalars; | ||
import graphql.kickstart.tools.GraphQLMutationResolver; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import graphql.schema.GraphQLScalarType; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import javax.servlet.http.Part; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class DummyMutation implements GraphQLMutationResolver { | ||
|
||
@Bean | ||
private GraphQLScalarType getUploadScalar() { | ||
// since the test doesn't inject this built-in Scalar, | ||
// so we inject here for test run purpose | ||
return ApolloScalars.Upload; | ||
} | ||
|
||
public List<String> uploadFiles(List<Part> files, DataFetchingEnvironment env) { | ||
List<Part> actualFiles = env.getArgument("files"); | ||
return actualFiles.stream().map(Part::getSubmittedFileName).collect(Collectors.toList()); | ||
} | ||
|
||
public String uploadFile(Part file, DataFetchingEnvironment env) { | ||
Part actualFile = env.getArgument("file"); | ||
return actualFile.getSubmittedFileName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
graphql-spring-boot-test/src/test/resources/upload-file.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mutation($file: Upload) { | ||
uploadFile(file: $file) | ||
} |
3 changes: 3 additions & 0 deletions
3
graphql-spring-boot-test/src/test/resources/upload-files.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mutation($files: [Upload]!) { | ||
uploadFiles(files: $files) | ||
} |