Cloudflare 中文文档
Analytics
Analytics
编辑这个页面
跳转官方原文档
Set theme to dark (⇧+D)

Execute a GraphQL query with curl

Using a plain curl to send a query provides the ability to slice-n-dice with the results and apply post-processing if needed. For example, converting results received from GraphQL API into a CSV format.

For more functionality, like auto-completion, schema exploring, etc., you can look at GraphQL clients.

GraphQL API expects JSON with two essentials fields: “query” and “variables”.

A query should be stripped from newline symbols and sent as a single-line string when the variables is an object full of values for all placeholders used in the query:

It is still possible to use a human-friendly query though. In the example below you can see how echo piped together with tr to provide a proper payload with curl: