Sunday, 21 August 2022

Spectaql for GraphQL API documentation

I had some moments lacking in clarity when I was trying Spectaql for the first time. The main issue was that cloning their source code and just trying to get things going gave me strange node.js package errors. 

 

https://github.com/anvilco/spectaql

 

So here are some quick instructions on what I did to generate the example API docs the Spectaql repo site recommends.  (I carried this out in Ubuntu Linux with node.js v.16.)

 

Make sure  you have git , nodejs (and npm) installed.

 

First clone the Spectaql project source code, so we can gain some  examples to learn from.

git clone https://github.com/anvilco/spectaql.git

This will download and create a project directory named 'spectaql'. In this source code directory, you will find an 'examples' directory.

ls -1 examples;

config.yml
customizations
data
output
themes

 

Make a new project directory elsewhere, e.g. 'spectaql_project1', and initialise it as a new project:

npm init

- accept all the defaults


Install the Spectaql packages into the project:

npm install --dev spectaql

 

Copy everything from the 'spectaql' project /examples directory from earlier into this directory.
The project directory should now look like:

ls -1;

config.yml
customizations
data
node_modules
output
package.json
package-lock.json
public
themes


Run this to generate Spectaql API docs:

npx spectaql config.yml


Check the new /public folder that should be created. This is where the generated API docs get outputted.

Open the 'index.html' file in there in a browser.

 

SpectaQL generated document