Skip to content

Commit

Permalink
fix: add support for enum args in query encoder (#2994)
Browse files Browse the repository at this point in the history
  • Loading branch information
laststylebender14 authored Oct 12, 2024
1 parent 052e037 commit 1679aea
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/http/query_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub fn convert_value(value: &async_graphql::Value) -> Option<String> {
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,
}
}
Expand Down
17 changes: 17 additions & 0 deletions tests/core/snapshots/test-enum-as-argument.md_0.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
source: tests/core/spec.rs
expression: response
---
{
"status": 200,
"headers": {
"content-type": "application/json"
},
"body": {
"data": {
"user": {
"name": "Json Schema"
}
}
}
}
21 changes: 21 additions & 0 deletions tests/core/snapshots/test-enum-as-argument.md_client.snap
Original file line number Diff line number Diff line change
@@ -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
}
21 changes: 21 additions & 0 deletions tests/core/snapshots/test-enum-as-argument.md_merged.snap
Original file line number Diff line number Diff line change
@@ -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!
}
39 changes: 39 additions & 0 deletions tests/execution/test-enum-as-argument.md
Original file line number Diff line number Diff line change
@@ -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 } }"
```

1 comment on commit 1679aea

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 7.55ms 3.34ms 39.29ms 73.43%
Req/Sec 3.37k 409.44 4.38k 94.25%

402625 requests in 30.02s, 772.69MB read

Requests/sec: 13411.66

Transfer/sec: 25.74MB

Please sign in to comment.