Skip to content

commitspark/example-http-express

Repository files navigation

Commitspark Example: Expose the Commitspark GraphQL API over HTTP using Express

This repository contains example code for Commitspark, the workflow-first Content Management System based on Git and GraphQL.


If you want to expose the GraphQL endpoint and schema generated by Commitspark over HTTP, the Commitspark GraphQL library can be wrapped in a web server such as Express. This repository here holds an example implementation of such a server, configured to manage content in a GitHub-based content repository.

In case you simply want to work with content in your own JavaScript- or TypeScript-based application, you may be better off by running queries and mutations directly against the Commitspark GraphQL library, without first going through HTTP. If this is the case, this example here is not relevant for you.

Starting the Commitspark Express server

  1. Run npm install

  2. Obtain a GitHub "personal access token (classic)" according to the GitHub documentation from here. Make sure to select the top-level scope repo.

  3. Get the repository owner and repository name for your content repository.

    For example, a repository at https://github.com/my-org/my-content-repository has owner my-org and repository name my-content-repository.

  4. Copy .env.dist to .env and fill in your repository owner, name, and GitHub access token.

  5. Compile your code with npm run build (and do so again after every code change).

  6. Run your server with npm run start.

The GraphQL endpoint is then available under http://localhost:3000/main/graphql and the generated GraphQL schema as plaintext under http://localhost:3000/main/schema (where main is the name of a valid branch in your content repository).

About

Commitspark example to expose the Commitspark GraphQL API over HTTP

Resources

License

Stars

Watchers

Forks