|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | +<meta charset="utf-8" /> |
| 5 | +<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"> |
| 6 | +<title>WebTau: Customized Graphql Urls</title> |
| 7 | +<link rel="stylesheet" type="text/css" href="/webtau/static/css/katex.min.css"> |
| 8 | +<link rel="stylesheet" type="text/css" href="/webtau/static/main.css"> |
| 9 | +<link rel="stylesheet" type="text/css" href="/webtau/logo.css"> |
| 10 | +<link rel="stylesheet" type="text/css" href="/webtau/static/css/global-overrides.css"> |
| 11 | +</head> |
| 12 | +<link rel="shortcut icon" href="/webtau/favicon.png"type="image/ico"/> |
| 13 | +<body class="theme-znai-dark"> |
| 14 | +<script>(function() { |
| 15 | + var themeNameKey = 'znaiTheme'; |
| 16 | + var darkThemeName = 'znai-dark'; |
| 17 | + var lightThemeName = 'default'; |
| 18 | + |
| 19 | + var znaiTheme = { |
| 20 | + changeHandlers: [], |
| 21 | + addChangeHandler(handler) { |
| 22 | + this.changeHandlers.push(handler); |
| 23 | + }, |
| 24 | + removeChangeHandler(handler) { |
| 25 | + var idx = this.changeHandlers.indexOf(handler); |
| 26 | + this.changeHandlers.splice(idx, 1); |
| 27 | + }, |
| 28 | + set(name) { |
| 29 | + this.name = name; |
| 30 | + document.body.className = 'theme-' + name; |
| 31 | + |
| 32 | + var idx = 0; |
| 33 | + var len = this.changeHandlers.length; |
| 34 | + for (; idx < len; idx++) { |
| 35 | + this.changeHandlers[idx](name); |
| 36 | + } |
| 37 | + }, |
| 38 | + setExplicitly(name) { |
| 39 | + storeThemeName(name); |
| 40 | + this.set(name); |
| 41 | + }, |
| 42 | + setExplicitlyIfNotSetAlready(name) { |
| 43 | + const themeName = getStoredThemeName(); |
| 44 | + if (themeName) { |
| 45 | + return |
| 46 | + } |
| 47 | + |
| 48 | + this.setExplicitly(name) |
| 49 | + }, |
| 50 | + toggle() { |
| 51 | + this.setExplicitly(this.name === lightThemeName ? darkThemeName : lightThemeName) |
| 52 | + } |
| 53 | + }; |
| 54 | + |
| 55 | + var mediaThemeName = setLightMatchMediaListenerAndGetThemeName() |
| 56 | + var themeName = getStoredThemeName() || mediaThemeName; |
| 57 | + znaiTheme.set(themeName); |
| 58 | + |
| 59 | + window.znaiTheme = znaiTheme; |
| 60 | + |
| 61 | + function getStoredThemeName() { |
| 62 | + return localStorage.getItem(themeNameKey); |
| 63 | + } |
| 64 | + |
| 65 | + function storeThemeName(name) { |
| 66 | + return localStorage.setItem(themeNameKey, name); |
| 67 | + } |
| 68 | + |
| 69 | + function setLightMatchMediaListenerAndGetThemeName() { |
| 70 | + if (!window.matchMedia) { |
| 71 | + return darkThemeName; |
| 72 | + } |
| 73 | + |
| 74 | + var lightQuery = window.matchMedia('(prefers-color-scheme: light)'); |
| 75 | + lightQuery.addListener(function (e) { |
| 76 | + const newThemeName = e.matches ? lightThemeName : darkThemeName; |
| 77 | + znaiTheme.setExplicitly(newThemeName); |
| 78 | + }); |
| 79 | + |
| 80 | + return lightQuery.matches ? lightThemeName : darkThemeName; |
| 81 | + } |
| 82 | +})()</script> |
| 83 | +<div id="znai"><div id="znai-initial-page-loading" style="margin: -20px 0 0 -20px; padding: 0 40px 40px 0; width: 100vw; height: 100vh; display: flex; justify-content: center; align-items: center"> |
| 84 | + <div></div> |
| 85 | +</div><section style="max-width: 640px; margin-left: auto; margin-right: auto;"> |
| 86 | +<article> |
| 87 | +<header><h1>Customizing the GraphQL Endpoint</h1></header> |
| 88 | +<p>By default, webtau assumes that all requests are made to a /graphql endpoint. The config value graphQLEndpoint can be set to use a non-standard endpoint, e.g. graphQLEndpoint=/api/graphql .Webtau also decorates the query with a (typically ignored) query parameter that contains the request's operationName , e.g. /graphql?operation=myOperation . This makes execution logs as well as webtau's step reports easier to read and debug, especially since the operation's name is part of the request's payload and is usually not logged by request loggers. If you want to turn this feature off, set the config value for graphQLShowOperationAsQueryParam to false .In order to customize the graphQL URL in different ways, you need to implement a GraphQLHttpConfiguration and ensure it gets loaded at runtime via the Java ServiceLoader.Here is an example in groovy: package org.testingisdocumenting.webtau.graphql import org.testingisdocumenting.webtau.graphql.config.GraphQLHttpConfiguration import org.testingisdocumenting.webtau.graphql.model.GraphQLRequest class CustomGraphQLHttpConfiguration implements GraphQLHttpConfiguration { // Note: our test server requires the graphql endpoint to start with "graphql" public static final CUSTOM_GRAPHQL_ENDPOINT = 'graphql-custom' @Override String requestUrl(String url, GraphQLRequest graphQLRequest) { if (null != graphQLRequest.operationName && !graphQLRequest.operationName.isEmpty()) { return "${CUSTOM_GRAPHQL_ENDPOINT}?operation=${graphQLRequest.operationName}" } return url } }</p> |
| 89 | +</article> |
| 90 | +</section> |
| 91 | +</div> |
| 92 | +<script type="text/javascript" src="/webtau/toc.js"></script> |
| 93 | +<script type="text/javascript" src="/webtau/documentation-references.js"></script> |
| 94 | +<script type="text/javascript" src="/webtau/assets.js"></script> |
| 95 | +<script type="text/javascript" src="/webtau/static/main.js"></script> |
| 96 | +<script type="text/javascript" src="/webtau/search-index.js"></script> |
| 97 | +<script> |
| 98 | +document.getElementById('znai').innerHTML = ''; |
| 99 | +/*<!--*/ |
| 100 | +ReactDOM.render(React.createElement(Documentation, { |
| 101 | + "docMeta" : { |
| 102 | + "viewOn" : { |
| 103 | + "link" : "https://github.com/testingisdocumenting/webtau/tree/master/webtau-docs/znai", |
| 104 | + "title" : "View On GitHub" |
| 105 | + }, |
| 106 | + "id" : "webtau", |
| 107 | + "title" : "WebTau", |
| 108 | + "type" : "Guide", |
| 109 | + "previewEnabled" : false, |
| 110 | + "allowedGroups" : [ "admin" ] |
| 111 | + }, |
| 112 | + "page" : { |
| 113 | + "type" : "Page", |
| 114 | + "content" : [ { |
| 115 | + "title" : "Customizing the GraphQL Endpoint", |
| 116 | + "id" : "customizing-the-graphql-endpoint", |
| 117 | + "type" : "Section", |
| 118 | + "content" : [ { |
| 119 | + "type" : "Paragraph", |
| 120 | + "content" : [ { |
| 121 | + "text" : "By default, webtau assumes that all requests are made to a ", |
| 122 | + "type" : "SimpleText" |
| 123 | + }, { |
| 124 | + "code" : "/graphql", |
| 125 | + "type" : "InlinedCode" |
| 126 | + }, { |
| 127 | + "text" : " endpoint. The config value ", |
| 128 | + "type" : "SimpleText" |
| 129 | + }, { |
| 130 | + "code" : "graphQLEndpoint", |
| 131 | + "type" : "InlinedCode" |
| 132 | + }, { |
| 133 | + "text" : " can be set to use a non-standard endpoint, e.g. ", |
| 134 | + "type" : "SimpleText" |
| 135 | + }, { |
| 136 | + "code" : "graphQLEndpoint=/api/graphql", |
| 137 | + "type" : "InlinedCode" |
| 138 | + }, { |
| 139 | + "text" : ".", |
| 140 | + "type" : "SimpleText" |
| 141 | + } ] |
| 142 | + }, { |
| 143 | + "type" : "Paragraph", |
| 144 | + "content" : [ { |
| 145 | + "text" : "Webtau also decorates the query with a (typically ignored) query parameter that contains the request's ", |
| 146 | + "type" : "SimpleText" |
| 147 | + }, { |
| 148 | + "code" : "operationName", |
| 149 | + "type" : "InlinedCode" |
| 150 | + }, { |
| 151 | + "text" : ", e.g. ", |
| 152 | + "type" : "SimpleText" |
| 153 | + }, { |
| 154 | + "code" : "/graphql?operation=myOperation", |
| 155 | + "type" : "InlinedCode" |
| 156 | + }, { |
| 157 | + "text" : ". This makes execution logs as well as webtau's step reports easier to read and debug, especially since the operation's name is part of the request's payload and is usually not logged by request loggers.", |
| 158 | + "type" : "SimpleText" |
| 159 | + }, { |
| 160 | + "type" : "SoftLineBreak" |
| 161 | + }, { |
| 162 | + "text" : "If you want to turn this feature off, set the config value for ", |
| 163 | + "type" : "SimpleText" |
| 164 | + }, { |
| 165 | + "code" : "graphQLShowOperationAsQueryParam", |
| 166 | + "type" : "InlinedCode" |
| 167 | + }, { |
| 168 | + "text" : " to ", |
| 169 | + "type" : "SimpleText" |
| 170 | + }, { |
| 171 | + "code" : "false", |
| 172 | + "type" : "InlinedCode" |
| 173 | + }, { |
| 174 | + "text" : ".", |
| 175 | + "type" : "SimpleText" |
| 176 | + } ] |
| 177 | + }, { |
| 178 | + "type" : "Paragraph", |
| 179 | + "content" : [ { |
| 180 | + "text" : "In order to customize the graphQL URL in different ways, you need to implement a ", |
| 181 | + "type" : "SimpleText" |
| 182 | + }, { |
| 183 | + "code" : "GraphQLHttpConfiguration", |
| 184 | + "type" : "InlinedCode" |
| 185 | + }, { |
| 186 | + "text" : " and ensure it gets loaded at runtime via the Java ServiceLoader.", |
| 187 | + "type" : "SimpleText" |
| 188 | + } ] |
| 189 | + }, { |
| 190 | + "type" : "Paragraph", |
| 191 | + "content" : [ { |
| 192 | + "text" : "Here is an example in groovy:", |
| 193 | + "type" : "SimpleText" |
| 194 | + } ] |
| 195 | + }, { |
| 196 | + "lang" : "groovy", |
| 197 | + "snippet" : "package org.testingisdocumenting.webtau.graphql\n\nimport org.testingisdocumenting.webtau.graphql.config.GraphQLHttpConfiguration\nimport org.testingisdocumenting.webtau.graphql.model.GraphQLRequest\n\nclass CustomGraphQLHttpConfiguration implements GraphQLHttpConfiguration {\n // Note: our test server requires the graphql endpoint to start with \"graphql\"\n public static final CUSTOM_GRAPHQL_ENDPOINT = 'graphql-custom'\n\n @Override\n String requestUrl(String url, GraphQLRequest graphQLRequest) {\n if (null != graphQLRequest.operationName && !graphQLRequest.operationName.isEmpty()) {\n return \"${CUSTOM_GRAPHQL_ENDPOINT}?operation=${graphQLRequest.operationName}\"\n }\n return url\n }\n}", |
| 198 | + "title" : "Customized GraphQLHttpConfiguration adding the operation to the URL", |
| 199 | + "type" : "Snippet" |
| 200 | + } ] |
| 201 | + } ], |
| 202 | + "lastModifiedTime" : 1616434529902, |
| 203 | + "tocItem" : { |
| 204 | + "sectionTitle" : "GraphQL", |
| 205 | + "pageTitle" : "Customized Graphql Urls", |
| 206 | + "pageMeta" : { }, |
| 207 | + "dirName" : "GraphQL", |
| 208 | + "fileName" : "customized-graphql-urls", |
| 209 | + "viewOnRelativePath" : null, |
| 210 | + "pageSectionIdTitles" : [ { |
| 211 | + "title" : "Customizing the GraphQL Endpoint", |
| 212 | + "id" : "customizing-the-graphql-endpoint" |
| 213 | + } ] |
| 214 | + } |
| 215 | + }, |
| 216 | + "footer" : { |
| 217 | + "type" : "Footer", |
| 218 | + "content" : [ { |
| 219 | + "type" : "Paragraph", |
| 220 | + "content" : [ { |
| 221 | + "text" : "If you have documentation suggestions, features or bugs to report, please create ", |
| 222 | + "type" : "SimpleText" |
| 223 | + }, { |
| 224 | + "url" : "https://github.com/testingisdocumenting/webtau/issues", |
| 225 | + "isFile" : false, |
| 226 | + "type" : "Link", |
| 227 | + "content" : [ { |
| 228 | + "text" : "GitHub Issue", |
| 229 | + "type" : "SimpleText" |
| 230 | + } ] |
| 231 | + } ] |
| 232 | + }, { |
| 233 | + "type" : "Paragraph", |
| 234 | + "content" : [ { |
| 235 | + "text" : "Contributions are welcome", |
| 236 | + "type" : "SimpleText" |
| 237 | + } ] |
| 238 | + } ] |
| 239 | + } |
| 240 | +}), document.getElementById("znai")); |
| 241 | +/*-->*/ |
| 242 | + |
| 243 | +</script> |
| 244 | + |
| 245 | +</body> |
| 246 | +</html> |
0 commit comments