Create GraphQL Server is a tool for building GraphQL apps with MongoDB by Tom Coleman. Tom has a good introductory post on CGS here and here. In the following post, I'll show how to get the project working on a Raspberry Pi.
The main problem that stops Create GraphQL Server from working on the Pi is the lack of the npm mongo-prebuilt package for the Pi (armf architecture). The workaround is to install the armf mongodb package separately.
Here are the steps
Before installing Create GraphQL Server, install mongo.
sudo apt-get install -y mongodb-server
This will also start mongodb on the default 27107 port. The configuration file can be found at /etc/mongodb.conf and the logfile is at /var/log/mongodb/mongodb.log.
Start with the standard steps:
sudo npm install -g create-graphql-server curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - sudo echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get update && sudo apt-get install yarn
Create a test project
create-graphql-server init test cd test
You'll have to make the following modifications to the project to work on the Pi
MONGO_PORT = 27017, MONGO_URL = 'mongodb://localhost:27017/database'
Use npm to build the package instead of Yarn:
npm install
Run your test project with npm:
npm start
You should now be able to bring up GraphiQL at http://localhost:3000/graphiql and perform actual GraphQL queries at http://localhost:3000/graphql.
Add a Systemd startup file for your new GraphQL service. Create the file /lib/systemd/system/cgs-tasklist.service:
[Unit] Description=Create-Graphql-Server tasklist-demo-server Documentation=http://localhost:3000 After=network.target [Service] Environment=NODE_PORT=3000 Type=simple User=pi ExecStart=/usr/bin/npm /home/pi/graphql/tasklist-demo-server WorkingDirectory=/home/pi/graphql/tasklist-demo-server Restart=on-failure [Install] WantedBy=multi-user.target
Reload the systemd configuration:
sudo systemctl daemon-reload sudo systemctl start cgs-tasklist