Open the terminal and set up a quick virtual environment like the following:
python3 -m venv venv;
. venv/bin/activate;
pip install --upgrade pip
Now, you're ready to install dependencies for your project with pip:
pip install flask requests
You've installed Flask, a microframework that you'll use for the simple web app to wrap data sent from GraphQL API.
You'll also need requests for authentication and to be able to fetch data from the Hygraph GraphQL API.
To configure the flask app location, set up an environment variable with the name of your application (say, api.py file):
export FLASK_APP = api.py
In this api.py file, create the simple Flask setup.
Type flask run
in the terminal and open the browser on localhost
with your endpoint to see the app running.
To authenticate your app on Hygraph, you need to know the endpoint that you want to access, the GraphQL query you want to send to the request, and the token generated by Hygraph.
To get the endpoint of your Hygraph application, navigate to the Project settings tab on the left and select Endpoints inside API Access page. Copy the endpoint under Content API and paste it somewhere.
If you scroll down on the same API Access page, you'll see a token generated by Hygraph called HYGRAPH_TOKEN. Under Value column, click on the token to copy it. Paste it somewhere, you'll need it.
export URL = <Content API endpoint>
export HYGRAPH_TOKEN = <HYGRAPH_TOKEN>