-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add integration test for onResponseBody
- Loading branch information
1 parent
1a1ecc4
commit 379dd34
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": { | ||
"hello": { | ||
"name": "Leanne Graham - Changed by JS" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
source: tests/core/spec.rs | ||
expression: formatted | ||
--- | ||
scalar Bytes | ||
|
||
scalar Date | ||
|
||
scalar DateTime | ||
|
||
scalar Email | ||
|
||
scalar Empty | ||
|
||
scalar Int128 | ||
|
||
scalar Int16 | ||
|
||
scalar Int32 | ||
|
||
scalar Int64 | ||
|
||
scalar Int8 | ||
|
||
scalar JSON | ||
|
||
scalar PhoneNumber | ||
|
||
type Query { | ||
hello: User! | ||
} | ||
|
||
scalar UInt128 | ||
|
||
scalar UInt16 | ||
|
||
scalar UInt32 | ||
|
||
scalar UInt64 | ||
|
||
scalar UInt8 | ||
|
||
scalar Url | ||
|
||
type User { | ||
id: Int! | ||
name: String! | ||
} | ||
|
||
schema { | ||
query: Query | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
source: tests/core/spec.rs | ||
expression: formatter | ||
--- | ||
schema @server @upstream(baseURL: "https://jsonplaceholder.typicode.com") @link(src: "test.js", type: Script) { | ||
query: Query | ||
} | ||
|
||
type Query { | ||
hello: User! @http(path: "/users/1", onResponseBody: "onResponse") | ||
} | ||
|
||
type User { | ||
id: Int! | ||
name: String! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Js Customize the Response with onResponseBody. | ||
|
||
```js @file:test.js | ||
function onResponse({response}) { | ||
let body = JSON.parse(response.body); | ||
body.name = body.name + " - Changed by JS"; | ||
response.body = JSON.stringify(body); | ||
return {response}; | ||
} | ||
``` | ||
|
||
```graphql @config | ||
schema @server @upstream(baseURL: "https://jsonplaceholder.typicode.com") @link(type: Script, src: "test.js") { | ||
query: Query | ||
} | ||
|
||
type Query { | ||
hello: User! @http(path: "/users/1", onResponseBody: "onResponse") | ||
} | ||
|
||
type User { | ||
id: Int! | ||
name: String! | ||
} | ||
``` | ||
|
||
```yml @mock | ||
- request: | ||
method: GET | ||
url: https://jsonplaceholder.typicode.com/users/1 | ||
response: | ||
status: 200 | ||
body: | ||
id: 1 | ||
name: Leanne Graham | ||
``` | ||
|
||
```yml @test | ||
- method: POST | ||
url: http://localhost:8080/graphql | ||
body: | ||
query: query { hello { name } } | ||
``` |