Docs 菜单
Docs 主页
/ /
Atlas App Services
/ /

从 CLI 运行 GraphQL 操作

在此页面上

  • Overview
  • 运行查询
  • 运行修改

您可以通过终端或命令行界面访问权限应用的Atlas GraphQL API 。 GraphQL通过HTTP运行,因此CLI可以是标准HTTP客户端,如curl ,也可以是专门的GraphQL CLI,如 graphqurl。

要将 GraphQL 请求发送到您的应用,您需要满足以下条件:

  • 您的应用程序 ID。

  • 有效的用户访问令牌。 有关如何获取访问令牌的详细信息,请参阅对 GraphQL 请求进行身份验证。

gq https://services.cloud.mongodb.com/api/client/v2.0/app/<Your App ID>/graphql \
-H 'Authorization: Bearer <Valid Access Token>' \
-q 'query AllMoviesFromYear($year: Int!) { movies(query: { year: $year }) { title year runtime } }' \
-v 'year=2000'
curl https://services.cloud.mongodb.com/api/client/v2.0/app/<Your App ID>/graphql \
-X POST \
-H 'Authorization: Bearer <Valid Access Token>' \
-d '{ "query": "query AllMoviesFromYear($year: Int!) { movies(query: { year: $year }) { title year runtime } }",
"variables": { "year": 2000 } }'
gq https://services.cloud.mongodb.com/api/client/v2.0/app/<Your App ID>/graphql \
-H 'Authorization: Bearer <Valid Access Token>' \
-q 'mutation UpdateMovieTitle($oldTitle: String!, $newTitle: String!) { updateOneMovie(query: { title: $oldTitle } set: { title: $newTitle }) { title year } }'
-v 'oldTitle=The Matrix Reloaded'
-v 'newTitle=The Matrix 2'
curl https://services.cloud.mongodb.com/api/client/v2.0/app/<Your App ID>/graphql \
-X POST \
-H 'Authorization: Bearer <Valid Access Token>' \
-d '{ "query": "mutation UpdateMovieTitle($oldTitle: String!, $newTitle: String!) { updateOneMovie(query: { title: $oldTitle } set: { title: $newTitle }) { title year } }",
"variables": { "oldTitle": "The Matrix Reloaded", "newTitle": "The Matrix 2" } }'

后退

定义自定义解析程序