通过curl发出Github GraphQL请求

时间:2018-03-21 03:31:40

标签: post github graphql github-graphql

以下GraphQL查询runs perfectly fine in Github GraphQL Explorer

$ cat GraphQL_query.graphql
query {
  __schema {
    types {
      name
      kind
      description
      fields {
        name
      }
    }
  }
}

但是,当我通过curl发送时:

curl -H "Authorization: bearer token" -X POST -d "`cat GraphQL_query.graphql`" https://api.github.com/graphql

我会得到:

{
  "message": "Problems parsing JSON",
  "documentation_url": "https://developer.github.com/v4"
}

怎么了?我怎样才能使它有效? THX。

1 个答案:

答案 0 :(得分:2)

curl语法对于该查询看起来像这样:

$ curl -H "Authorization: Bearer $GITHUB_PRODUCTION_TOKEN" https://api.github.com/graphql -X POST -d '{"query":"query { __schema { types { name kind description fields { name } } } }","variables":"{}"}'