From 1679aea7bac3a8a89a426669fe5da33dfd670ad1 Mon Sep 17 00:00:00 2001 From: laststylebender <43403528+laststylebender14@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:43:03 +0530 Subject: [PATCH] fix: add support for enum args in query encoder (#2994) --- src/core/http/query_encoder.rs | 1 + .../snapshots/test-enum-as-argument.md_0.snap | 17 ++++++++ .../test-enum-as-argument.md_client.snap | 21 ++++++++++ .../test-enum-as-argument.md_merged.snap | 21 ++++++++++ tests/execution/test-enum-as-argument.md | 39 +++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 tests/core/snapshots/test-enum-as-argument.md_0.snap create mode 100644 tests/core/snapshots/test-enum-as-argument.md_client.snap create mode 100644 tests/core/snapshots/test-enum-as-argument.md_merged.snap create mode 100644 tests/execution/test-enum-as-argument.md diff --git a/src/core/http/query_encoder.rs b/src/core/http/query_encoder.rs index af6ca4f310..208c7a9cc4 100644 --- a/src/core/http/query_encoder.rs +++ b/src/core/http/query_encoder.rs @@ -64,6 +64,7 @@ pub fn convert_value(value: &async_graphql::Value) -> Option { async_graphql::Value::String(s) => Some(s.to_string()), async_graphql::Value::Number(n) => Some(n.to_string()), async_graphql::Value::Boolean(b) => Some(b.to_string()), + async_graphql::Value::Enum(e) => Some(e.to_string()), _ => None, } } diff --git a/tests/core/snapshots/test-enum-as-argument.md_0.snap b/tests/core/snapshots/test-enum-as-argument.md_0.snap new file mode 100644 index 0000000000..65b72721d6 --- /dev/null +++ b/tests/core/snapshots/test-enum-as-argument.md_0.snap @@ -0,0 +1,17 @@ +--- +source: tests/core/spec.rs +expression: response +--- +{ + "status": 200, + "headers": { + "content-type": "application/json" + }, + "body": { + "data": { + "user": { + "name": "Json Schema" + } + } + } +} diff --git a/tests/core/snapshots/test-enum-as-argument.md_client.snap b/tests/core/snapshots/test-enum-as-argument.md_client.snap new file mode 100644 index 0000000000..bbeebabcdc --- /dev/null +++ b/tests/core/snapshots/test-enum-as-argument.md_client.snap @@ -0,0 +1,21 @@ +--- +source: tests/core/spec.rs +expression: formatted +--- +type Query { + user(id: Int!, test: Test): User +} + +enum Test { + A + B +} + +type User { + id: Int! + name: String! +} + +schema { + query: Query +} diff --git a/tests/core/snapshots/test-enum-as-argument.md_merged.snap b/tests/core/snapshots/test-enum-as-argument.md_merged.snap new file mode 100644 index 0000000000..79a95bb7c4 --- /dev/null +++ b/tests/core/snapshots/test-enum-as-argument.md_merged.snap @@ -0,0 +1,21 @@ +--- +source: tests/core/spec.rs +expression: formatter +--- +schema @server @upstream(baseURL: "http://jsonplaceholder.typicode.com") { + query: Query +} + +enum Test { + A + B +} + +type Query { + user(id: Int!, test: Test): User @http(path: "/users/{{.args.id}}", query: [{key: "enum", value: "{{.args.test}}"}]) +} + +type User { + id: Int! + name: String! +} diff --git a/tests/execution/test-enum-as-argument.md b/tests/execution/test-enum-as-argument.md new file mode 100644 index 0000000000..917b0a7e4b --- /dev/null +++ b/tests/execution/test-enum-as-argument.md @@ -0,0 +1,39 @@ +# test enum as argument + +```graphql @config +schema @server @upstream(baseURL: "http://jsonplaceholder.typicode.com") { + query: Query +} + +type Query { + user(id: Int!, test: Test): User @http(path: "/users/{{.args.id}}", query: [{key: "enum", value: "{{.args.test}}"}]) +} + +enum Test { + A + B +} + +type User { + id: Int! + name: String! +} +``` + +```yml @mock +- request: + method: GET + url: http://jsonplaceholder.typicode.com/users/1?enum=A + response: + status: 200 + body: + id: 1 + name: Json Schema +``` + +```yml @test +- method: POST + url: http://localhost:8080/graphql + body: + query: "query { user(id: 1, test: A) { name } }" +```