-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update file-upload example (#321)
- Fixed the file-upload example: it is necessary to declare at least one query, otherwise the graphql-java-tools throws exceptions during the schema parsing - Replaced the return boolean type with a UploadedFile type containing the filename, type and the content of the textual file uploaded - Added a README explaining how to run it Refs: #94
- Loading branch information
1 parent
0d196d6
commit 909a296
Showing
4 changed files
with
57 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# File Upload | ||
This Spring example shows how the upload operation works using GraphQL and the Apollo Upload type. | ||
|
||
## How to run | ||
- Create a file: `echo 'Hello World!' > hello-world.txt` | ||
- Run the example: `../gradlew bootRun` | ||
- Make a GraphQL request: | ||
```sh | ||
curl --location 'http://localhost:9000/graphql' \ | ||
--form 'operations="{\"query\": \"mutation upload($file:Upload){ upload(file: $file){filename type content}}\"}"' \ | ||
--form 'map="{\"blob\": [\"variables.file\"]}"' \ | ||
--form 'blob=@"./hello-world.txt"' | ||
``` | ||
|
||
If the file is successfully uploaded, this is the response received and the log shown: | ||
```json | ||
{ | ||
"data": { | ||
"upload": { | ||
"filename": "hello-world.txt", | ||
"type": "text/plain", | ||
"content": "Hello World!\n" | ||
} | ||
} | ||
} | ||
|
||
``` | ||
|
||
```log | ||
INFO 1584868 --- [nio-9000-exec-7] upload.UploadMutation: File uploaded: {type=text/plain, filename=hello-world.txt, content=Hello World!} | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
scalar Upload | ||
|
||
type Query { | ||
type UploadedFile { | ||
filename: String | ||
type: String | ||
content: String | ||
} | ||
|
||
# The hello query declaration is necessary since the graphql-java-tools requires at least one query | ||
type Query { | ||
hello: String | ||
} | ||
|
||
type Mutation { | ||
upload(file: Upload): Boolean | ||
upload(file: Upload): UploadedFile | ||
} |