Skip to content

Commit

Permalink
Add integration test for non-nullable files
Browse files Browse the repository at this point in the history
resolves #4708

This commit adds a test to ensure that non-nullable file uploads
still work as expected.
  • Loading branch information
nicholascioli committed Mar 7, 2024
1 parent d5db9f8 commit 0a909ed
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions apollo-router/tests/fixtures/file_upload/schema.graphql
Expand Up @@ -82,6 +82,7 @@ type Mutation
@join__type(graph: UPLOADS_CLONE)
{
singleUpload(file: Upload): File @join__field(graph: UPLOADS)
singleUploadNonNull(file: Upload!): File! @join__field(graph: UPLOADS)
singleUploadClone(file: UploadClone): FileClone @join__field(graph: UPLOADS_CLONE)
multiUpload(files: [Upload!]!): [File!]! @join__field(graph: UPLOADS)
nestedUpload(nested: NestedUpload): File @join__field(graph: UPLOADS)
Expand Down
53 changes: 53 additions & 0 deletions apollo-router/tests/integration/file_upload.rs
Expand Up @@ -373,6 +373,59 @@ async fn it_supports_compression() -> Result<(), BoxError> {
.await
}

#[tokio::test(flavor = "multi_thread")]
async fn it_supports_non_nullable_file() -> Result<(), BoxError> {
use reqwest::multipart::Form;
use reqwest::multipart::Part;

// Construct a manual request for non nullable checks
let request = Form::new()
.part(
"operations",
Part::text(
serde_json::json!({
"query": "mutation SomeMutation($file0: Upload!) {
file0: singleUploadNonNull(file: $file0) { filename body }
}",
"variables": {
"file0": null,
},
})
.to_string(),
),
)
.part(
"map",
Part::text(
serde_json::json!({
"0": ["variables.file0"],
})
.to_string(),
),
)
.part("0", Part::text("file0 contents").file_name("file0"));

helper::FileUploadTestServer::builder()
.config(FILE_CONFIG)
.handler(make_handler!(helper::echo_single_file))
.request(request)
.subgraph_mapping("uploads", "/")
.build()
.run_test(|request| {
insta::assert_json_snapshot!(request, @r###"
{
"data": {
"file0": {
"filename": "file0",
"body": "file0 contents"
}
}
}
"###);
})
.await
}

#[tokio::test(flavor = "multi_thread")]
async fn it_supports_nested_file() -> Result<(), BoxError> {
use reqwest::multipart::Form;
Expand Down

0 comments on commit 0a909ed

Please sign in to comment.