Graphql usage: Difference between revisions
From wikinotes
m (Will moved page Graphql: usage to Graphql usage without leaving a redirect) |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= | = HTTP Requests = | ||
<blockquote> | <blockquote> | ||
Graphql is a language, and it's schema is a large file defining all of the available types, queries, and mutations. | Graphql is a language, and it's schema is a large file defining all of the available types, queries, and mutations. | ||
Line 5: | Line 5: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
# query | # query | ||
curl -X POST \ | curl -X POST \ | ||
-H 'Content-Type: application/json' \ | -H 'Content-Type: application/json' \ | ||
-d '{"query": | -d '{"query": "query queryTask($id: ID!){ task(id: $id){ name } }", \ | ||
"variables" { " | "variables": {"id": "1"}}' \ | ||
http://127.0.0.1:8000 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 18: | Line 17: | ||
curl -X POST \ | curl -X POST \ | ||
-H 'Content-Type: application/json' \ | -H 'Content-Type: application/json' \ | ||
-d '{"query": | -d '{"query": "mutation createTask($name: String!){ createTask(name: $desc) { id name } }" \ | ||
"variables": { " | "variables": {"name": "clean kitchen"}}' \ | ||
http://127.0.0.1:8000 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- | </blockquote><!-- HTTP Requests --> | ||
= Web Interfaces = | |||
<blockquote> | |||
Most graphql API libraries include a web-interface you can interactively compose queries in.<br> | |||
They generally have features like syntax highlighting and tab completion. | |||
</blockquote><!-- Web Interfaces --> |
Latest revision as of 14:20, 4 September 2021
HTTP Requests
Graphql is a language, and it's schema is a large file defining all of the available types, queries, and mutations.
# query curl -X POST \ -H 'Content-Type: application/json' \ -d '{"query": "query queryTask($id: ID!){ task(id: $id){ name } }", \ "variables": {"id": "1"}}' \ http://127.0.0.1:8000# mutation curl -X POST \ -H 'Content-Type: application/json' \ -d '{"query": "mutation createTask($name: String!){ createTask(name: $desc) { id name } }" \ "variables": {"name": "clean kitchen"}}' \ http://127.0.0.1:8000
Web Interfaces
Most graphql API libraries include a web-interface you can interactively compose queries in.
They generally have features like syntax highlighting and tab completion.