Docs Menu
Docs Home
/ /
Atlas App Services
/ /

Run GraphQL Operations from a CLI

On this page

  • Overview
  • Run a Query
  • Run a Mutation

You can access your App's Atlas GraphQL API through a terminal or command line interface. GraphQL operates over HTTP, so the CLI can be a standard HTTP client, like curl, or a specialized GraphQL CLI, like graphqurl.

To send GraphQL requests to your app, you'll need the following:

  • Your App ID.

  • A valid user access token. For details on how to get an access token, see Authenticate GraphQL Requests.

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" } }'

Back

Define a Custom Resolver