hurl/integration/tests_ok/graphql.html

94 lines
7.0 KiB
HTML
Raw Normal View History

2022-11-23 14:10:31 +03:00
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"></span><span class="comment"># An unnamed simple query</span>
<span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/graphql</span></span>
<span class="multiline"><span class="line">```graphql</span>
<span class="line">{</span>
<span class="line"> allFilms {</span>
<span class="line"> films {</span>
<span class="line"> title</span>
<span class="line"> director</span>
<span class="line"> releaseDate</span>
<span class="line"> }</span>
<span class="line"> }</span>
<span class="line">}</span>
<span class="line">```</span></span>
</span><span class="response"><span class="line"></span>
<span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
2023-04-11 18:28:28 +03:00
<span class="line"><span class="section-header">[Asserts]</span></span>
2022-11-23 14:10:31 +03:00
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.data.allFilms.films"</span> <span class="filter-type">count</span> <span class="predicate-type">==</span> <span class="number">6</span></span>
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.data.allFilms.films[0].title"</span> <span class="predicate-type">==</span> <span class="string">"A New Hope"</span></span>
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.data.allFilms.films[0].director"</span> <span class="predicate-type">==</span> <span class="string">"George Lucas"</span></span>
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.data.allFilms.films[0].releaseDate"</span> <span class="predicate-type">==</span> <span class="string">"1977-05-25"</span></span>
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.data.allFilms.films[0].openingCrawl"</span> <span class="not">not</span> <span class="predicate-type">exists</span></span>
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.data.allFilms.films[1].title"</span> <span class="predicate-type">==</span> <span class="string">"The Empire Strikes Back"</span></span>
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.data.allFilms.films[2].title"</span> <span class="predicate-type">==</span> <span class="string">"Return of the Jedi"</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"></span>
<span class="line"></span><span class="comment"># Equivalent syntax by posting a JSON body</span>
<span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/graphql</span></span>
2023-04-17 14:05:34 +03:00
<span class="line"><span class="string">Content-Type</span>: <span class="string">application/json</span></span>
<span class="json"><span class="line">{"query":"{\n allFilms {\n films {\n title\n director\n releaseDate\n }\n }\n}"}</span></span>
</span><span class="response"><span class="line"></span>
<span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
2023-04-11 18:28:28 +03:00
<span class="line"><span class="section-header">[Asserts]</span></span>
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.data.allFilms.films"</span> <span class="filter-type">count</span> <span class="predicate-type">==</span> <span class="number">6</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"></span>
2022-11-23 14:10:31 +03:00
<span class="line"></span><span class="comment"># Full syntax for query</span>
<span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/graphql</span></span>
<span class="multiline"><span class="line">```graphql</span>
<span class="line">query Query {</span>
<span class="line"> allFilms {</span>
<span class="line"> films {</span>
<span class="line"> title</span>
<span class="line"> director</span>
<span class="line"> releaseDate</span>
<span class="line"> }</span>
<span class="line"> }</span>
<span class="line">}</span>
<span class="line">```</span></span>
</span><span class="response"><span class="line"></span>
<span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
2023-04-11 18:28:28 +03:00
<span class="line"><span class="section-header">[Asserts]</span></span>
2022-11-23 14:10:31 +03:00
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.data.allFilms.films"</span> <span class="filter-type">count</span> <span class="predicate-type">==</span> <span class="number">6</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"></span>
2022-11-23 14:10:31 +03:00
<span class="line"></span><span class="comment"># Query with variables:</span>
<span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/graphql</span></span>
<span class="multiline"><span class="line">```graphql</span>
<span class="line">query Person($id: ID!) {</span>
<span class="line"> person(id: $id) {</span>
<span class="line"> name</span>
<span class="line"> }</span>
<span class="line">}</span>
<span class="line"></span>
<span class="line">variables {</span>
<span class="line"> "id": "cGVvcGxlOjQ="</span>
<span class="line">}</span>
<span class="line">```</span></span>
</span><span class="response"><span class="line"></span>
<span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
2023-04-11 18:28:28 +03:00
<span class="line"><span class="section-header">[Asserts]</span></span>
2022-11-23 14:10:31 +03:00
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.data.person.name"</span> <span class="predicate-type">==</span> <span class="string">"Darth Vader"</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"></span>
<span class="line"></span><span class="comment"># Hurl variables can also be used:</span>
<span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/graphql</span></span>
2023-04-11 18:28:28 +03:00
<span class="line"><span class="section-header">[Options]</span></span>
2023-04-17 14:05:34 +03:00
<span class="line"><span class="string">variable</span>: id=<span class="string">cGVvcGxlOjQ=</span></span>
2022-11-23 14:10:31 +03:00
<span class="multiline"><span class="line">```graphql</span>
<span class="line">query Person($id: ID!) {</span>
<span class="line"> person(id: $id) {</span>
<span class="line"> name</span>
<span class="line"> }</span>
<span class="line">}</span>
<span class="line"></span>
<span class="line">variables {</span>
<span class="line"> "id": "{{id}}"</span>
<span class="line">}</span>
<span class="line">```</span></span>
</span><span class="response"><span class="line"></span>
<span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
2023-04-11 18:28:28 +03:00
<span class="line"><span class="section-header">[Asserts]</span></span>
2022-11-23 14:10:31 +03:00
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.data.person.name"</span> <span class="predicate-type">==</span> <span class="string">"Darth Vader"</span></span>
</span></span></code></pre>