Skip to content

Commit

Permalink
Add integration test for non-nullable files
Browse files Browse the repository at this point in the history
Existing integration tests for the file uploads plugin did not test for
non-nullable uploads. As this is realistically the more common case,
this commit adds a test to ensure that non-nullable files work as
expected.

This is necessary since the router does some substitution of the
variables for the file upload case which might cause validation issues
if not carefully tested.

Fixes #4708
  • Loading branch information
nicholascioli committed Mar 7, 2024
1 parent d5db9f8 commit fcec874
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 fcec874

Please sign in to comment.