This project builds a GraphQL API using the MongoDB Atlas Data API without writing any code.
You'll need to create a StepZen account first. Once you've got that set up, git clone this repository onto your machine and open the working directory:
git clone https://github.com/stepzen-dev/examples.git
cd examples/with-mongodb-atlas
Before you can run this example, you need to have a MongoDB Atlas account.
Follow the getting started documentation here to create an account and deploy a free cluster. Then, follow the instructions on the sample data page to load the cluster with some sample datasets.
Once you have loaded the sample data, you need to create an API Key to use the Data API. In your MongoDB Atlas console, click on Data API in the left hand nav, and click the Create API Key button. Copy and save your API Key, you will need it in the next step. Also copy the URL Endpoint, which will look like https://data.mongodb-api.com/app/<app-id>/endpoint/data/beta
. You will also need the app-id portion of that URL in the next step.
You can copy the file sample.config.yaml
to a new config.yaml
file:
cp stepzen/sample.config.yaml stepzen/config.yaml
In the new config.yaml
file, replace the value REPLACE_WITH_YOUR_DATA_API_KEY
with the key you just created and copied, and REPLACE_WITH_YOUR_DATA_API_APP_ID
with the Data API App ID, which should look something like data-xqgfu
(yours will be different!).
# stepzen/config.yaml
configurationset:
- configuration:
name: mongodb
apikey: REPLACE_WITH_YOUR_DATA_API_KEY
appid: data-REPLACE_WITH_YOUR_DATA_API_APP_ID
Open your terminal and install the StepZen CLI. You need to login here using the command: stepzen login
.
Start the GraphQL by running stepzen start
. After you've followed the prompts (you can accept the suggested endpoint name or add your own), a proxy of the GraphiQL playground becomes available at http://localhost/5001
which you can use to explore the GraphQL API. Also, the endpoint at which your GraphQL API is deployed gets logged in the terminal. You can query your GraphQL API from any application, browser, or IDE by providing the API Key linked to your account.
Try running the following query against your MongoDB Data API:
query MyQuery($filter: MongoFilter) {
listings(limit: 100, filter: $filter) {
name
beds
bedrooms
address {
market
}
property_type
}
}
with variables:
{
"filter": {
"address.market": "Istanbul"
}
}
You can learn more in the StepZen documentation. Questions? Head over to Discord or GitHub Discussions to ask questions.