From fcec87486aeb4300f0217e7df782a15e691c0a5c Mon Sep 17 00:00:00 2001 From: Nicholas Cioli Date: Thu, 7 Mar 2024 11:11:08 -0500 Subject: [PATCH] Add integration test for non-nullable files 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 --- .../tests/fixtures/file_upload/schema.graphql | 1 + .../tests/integration/file_upload.rs | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/apollo-router/tests/fixtures/file_upload/schema.graphql b/apollo-router/tests/fixtures/file_upload/schema.graphql index 07e301012c..4816f46fa8 100644 --- a/apollo-router/tests/fixtures/file_upload/schema.graphql +++ b/apollo-router/tests/fixtures/file_upload/schema.graphql @@ -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) diff --git a/apollo-router/tests/integration/file_upload.rs b/apollo-router/tests/integration/file_upload.rs index d1ff7a97c8..5081509027 100644 --- a/apollo-router/tests/integration/file_upload.rs +++ b/apollo-router/tests/integration/file_upload.rs @@ -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;