|
3 | 3 | <head> |
4 | 4 | <meta charset="utf-8" /> |
5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"> |
6 | | -<title>WebTau: Queries</title> |
| 6 | +<title>WebTau: Queries And Mutations</title> |
7 | 7 | <link rel="stylesheet" type="text/css" href="/webtau/static/css/katex.min.css"> |
8 | 8 | <link rel="stylesheet" type="text/css" href="/webtau/static/main.css"> |
9 | 9 | <link rel="stylesheet" type="text/css" href="/webtau/logo.css"> |
|
84 | 84 | <div></div> |
85 | 85 | </div><section style="max-width: 640px; margin-left: auto; margin-right: auto;"> |
86 | 86 | <article> |
87 | | -<header><h1>Executing Queries</h1></header> |
88 | | -<p>WebTau follows GraphQL's https://graphql.org/learn/serving-over-http/ Serving over HTTP best practices when invoking GraphQL servers over HTTP.It therefore assumes the server responds to requests to /graphql so you do not need to specify that in the URL in your configuration. Queries allow providing:a query stringvariablesan operation nameWebTau will default to issuing POST requests according to the https://graphql.org/learn/serving-over-http/#post-request best practices and will expect a 200 status code and a response with a data or errors field.The following example demonstrates most of these query features: package scenarios.graphql import static org.testingisdocumenting.webtau.WebTauGroovyDsl.* def listAllQuery = ''' { allTasks(uncompletedOnly: false) { id description } } ''' def taskByIdQuery = ''' query taskById($id: ID!) { taskById(id: $id) { id description completed } } ''' def completeMutation = ''' mutation complete($id: ID!) { complete(id: $id) } ''' scenario("list all tasks") { graphql.execute(listAllQuery) { // Execute a simple query with no variables errors.should == null // Validate there were no errors allTasks.id.should == ["a", "b", "c"] // Access response data via a shortcut allowing omitting of `body.data` body.data.allTasks.id.should == ["a", "b", "c"] } } scenario("complete a task") { graphql.execute(completeMutation, [id: "a"]) { // Execute a mutation with a variables map errors.should == null complete.should == true } graphql.execute(taskByIdQuery, [id: "a"]) { errors.should == null taskById.id.should == "a" taskById.completed.should == true } }</p> |
| 87 | +<header><h1>Executing Queries and Mutations</h1></header> |
| 88 | +<p>WebTau follows GraphQL's https://graphql.org/learn/serving-over-http/ Serving over HTTP best practices when invoking GraphQL servers over HTTP.It therefore assumes the server responds to requests to /graphql so you do not need to specify that in the URL in your configuration. Requests allow providing:a query/mutation stringvariablesan operation nameWebTau will default to issuing POST requests according to the https://graphql.org/learn/serving-over-http/#post-request best practices and will expect a 200 status code and a response with a data or errors field.The following example demonstrates most of these query features: package scenarios.graphql import static org.testingisdocumenting.webtau.WebTauGroovyDsl.* def listAllQuery = ''' { allTasks(uncompletedOnly: false) { id description } } ''' def taskByIdQuery = ''' query taskById($id: ID!) { taskById(id: $id) { id description completed } } ''' def completeMutation = ''' mutation complete($id: ID!) { complete(id: $id) } ''' scenario("list all tasks") { graphql.execute(listAllQuery) { // Execute a simple query with no variables errors.should == null // Validate there were no errors body.data.allTasks.id.should == ["a", "b", "c"] // Access response data with the full path allTasks.id.should == ["a", "b", "c"] // Access response data via a shortcut allowing omitting of `body.data` id.should == ["a", "b", "c"] // For single query requests, access response data via a shortcut allowing omitting of `body.data` and the query name } } scenario("complete a task") { graphql.execute(completeMutation, [id: "a"]) { // Execute a mutation with a variables map errors.should == null complete.should == true } graphql.execute(taskByIdQuery, [id: "a"]) { errors.should == null taskById.id.should == "a" taskById.completed.should == true } }</p> |
89 | 89 | </article> |
90 | 90 |
|
91 | 91 | <article> |
|
115 | 115 | "page" : { |
116 | 116 | "type" : "Page", |
117 | 117 | "content" : [ { |
118 | | - "title" : "Executing Queries", |
119 | | - "id" : "executing-queries", |
| 118 | + "title" : "Executing Queries and Mutations", |
| 119 | + "id" : "executing-queries-and-mutations", |
120 | 120 | "type" : "Section", |
121 | 121 | "content" : [ { |
122 | 122 | "type" : "Paragraph", |
|
154 | 154 | }, { |
155 | 155 | "type" : "SoftLineBreak" |
156 | 156 | }, { |
157 | | - "text" : "Queries allow providing:", |
| 157 | + "text" : "Requests allow providing:", |
158 | 158 | "type" : "SimpleText" |
159 | 159 | } ] |
160 | 160 | }, { |
|
166 | 166 | "content" : [ { |
167 | 167 | "type" : "Paragraph", |
168 | 168 | "content" : [ { |
169 | | - "text" : "a query string", |
| 169 | + "text" : "a query/mutation string", |
170 | 170 | "type" : "SimpleText" |
171 | 171 | } ] |
172 | 172 | } ] |
|
234 | 234 | } ] |
235 | 235 | }, { |
236 | 236 | "lang" : "groovy", |
237 | | - "snippet" : "package scenarios.graphql\n\nimport static org.testingisdocumenting.webtau.WebTauGroovyDsl.*\n\ndef listAllQuery = '''\n{\n allTasks(uncompletedOnly: false) {\n id\n description\n }\n}\n'''\n\ndef taskByIdQuery = '''\nquery taskById($id: ID!) {\n taskById(id: $id) {\n id\n description\n completed\n }\n}\n'''\n\ndef completeMutation = '''\nmutation complete($id: ID!) {\n complete(id: $id)\n}\n'''\n\nscenario(\"list all tasks\") {\n graphql.execute(listAllQuery) { // Execute a simple query with no variables\n errors.should == null // Validate there were no errors\n allTasks.id.should == [\"a\", \"b\", \"c\"] // Access response data via a shortcut allowing omitting of `body.data`\n body.data.allTasks.id.should == [\"a\", \"b\", \"c\"]\n }\n}\n\nscenario(\"complete a task\") {\n graphql.execute(completeMutation, [id: \"a\"]) { // Execute a mutation with a variables map\n errors.should == null\n complete.should == true\n }\n\n graphql.execute(taskByIdQuery, [id: \"a\"]) {\n errors.should == null\n taskById.id.should == \"a\"\n taskById.completed.should == true\n }\n}", |
| 237 | + "snippet" : "package scenarios.graphql\n\nimport static org.testingisdocumenting.webtau.WebTauGroovyDsl.*\n\ndef listAllQuery = '''\n{\n allTasks(uncompletedOnly: false) {\n id\n description\n }\n}\n'''\n\ndef taskByIdQuery = '''\nquery taskById($id: ID!) {\n taskById(id: $id) {\n id\n description\n completed\n }\n}\n'''\n\ndef completeMutation = '''\nmutation complete($id: ID!) {\n complete(id: $id)\n}\n'''\n\nscenario(\"list all tasks\") {\n graphql.execute(listAllQuery) { // Execute a simple query with no variables\n errors.should == null // Validate there were no errors\n body.data.allTasks.id.should == [\"a\", \"b\", \"c\"] // Access response data with the full path\n allTasks.id.should == [\"a\", \"b\", \"c\"] // Access response data via a shortcut allowing omitting of `body.data`\n id.should == [\"a\", \"b\", \"c\"] // For single query requests, access response data via a shortcut allowing omitting of `body.data` and the query name\n }\n}\n\nscenario(\"complete a task\") {\n graphql.execute(completeMutation, [id: \"a\"]) { // Execute a mutation with a variables map\n errors.should == null\n complete.should == true\n }\n\n graphql.execute(taskByIdQuery, [id: \"a\"]) {\n errors.should == null\n taskById.id.should == \"a\"\n taskById.completed.should == true\n }\n}", |
238 | 238 | "title" : "GraphQL example with a query, a mutation and variables", |
239 | 239 | "commentsType" : "inline", |
240 | 240 | "type" : "Snippet" |
|
274 | 274 | } ] |
275 | 275 | } ] |
276 | 276 | } ], |
277 | | - "lastModifiedTime" : 1597944757734, |
| 277 | + "lastModifiedTime" : 1604459318229, |
278 | 278 | "tocItem" : { |
279 | 279 | "sectionTitle" : "GraphQL", |
280 | | - "pageTitle" : "Queries", |
| 280 | + "pageTitle" : "Queries And Mutations", |
281 | 281 | "pageMeta" : { }, |
282 | 282 | "dirName" : "GraphQL", |
283 | | - "fileName" : "queries", |
| 283 | + "fileName" : "queries-and-mutations", |
284 | 284 | "viewOnRelativePath" : null, |
285 | 285 | "pageSectionIdTitles" : [ { |
286 | | - "title" : "Executing Queries", |
287 | | - "id" : "executing-queries" |
| 286 | + "title" : "Executing Queries and Mutations", |
| 287 | + "id" : "executing-queries-and-mutations" |
288 | 288 | }, { |
289 | 289 | "title" : "Response Assertions", |
290 | 290 | "id" : "response-assertions" |
|
0 commit comments