A GraphQL implementation to expose stack overflow resources (Comments, Posts, Answers, Votes, etc)
Stack Exchange doesn't have a GraphQL endpoint so I made one. For now, the live API above is in POC mode only as the schema is built. It is currently serving content from https://anime.stackexchange.com/ and is updated weekly with more to come as the pipeline & infra are beefed up & built out.
To run locally:
docker-compose up
and visit http://localhost:8080 to start using the playground or hit the endpoint with some queries! For example, to get information on a couple typical Q&A pages:
query posts {
allPostsCursor(first: 2) {
pageInfo {
hasNextPage
hasPreviousPage
}
edges {
cursor
node {
score
title
body
comments {
userId
text
}
answers {
score
body
comments {
userDisplayName
text
}
}
}
}
}
}
The server is also available as a docker container provided a separate backend exists:
docker run -e SERVER='<dbhost>' -e UNAME='<dbUname>' -e PASS='<dbPass>' snimmagadda/stack-exchange-graphql-server:latest
or to run from source:
go run cmd/server.goSome environment variables must be set to run locally
| Key | Type | Description | Example |
|---|---|---|---|
SERVER |
String | DB host | localhost |
SCHEMA |
String | app DB schema | stacke |
UNAME |
String | app DB username cred | appuser |
PASS |
String | app DB password cred | supersecret123 |
SERVER should be the hostname of a MySQL DB. In order to serve content, the GraphQL server expects a populated stacke schema.
TODO: configurable params...
go build cmd/server.goOptions for development are readily flexible with more streamlined routes to come... For now the following is available:
-
Run the backend only with docker (or tweak & use
docker-compose.yml)docker run --name test-mysql -e MYSQL_ROOT_PASSWORD=password -e MYSQL_ROOT_USER=root -e MYSQL_PASSWORD=password -d -p 3306:3306 mysql:5.7.26 -
~1K rows exist here will be used as inserts to your schema.
-
Create (or copy) a .env file with the variables in the table above set to configure the local GraphQL server.
-
Start the server:
go run cmd/server.go
TODOI'm probably going to do some refinement and swap to something like an Elastic backend but for now here's the early setup. XML dumps published by Stack Exchange are imported into an indexed relational backend using a job written with Spring Batch on a schedule. The graphql server reads from this backend to expose Stack Exchange data. Expect a minimal amount of latency because this is currently hosted in an App Service, which will spin down during periods of low-usage. If this happens, please be patient and the playground/requests should come blazing in after the first 'wakeup'. If this gets some traction, availability will be increased.
π€ Sai Nimmagadda
- Website: s11a.com
- Github: @snimmagadda1
This project is currently in build-mode. Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a βοΈ if this project helped you!
Copyright Β© 2020 Sai Nimmagadda.
This project is MIT licensed.
This README was generated with β€οΈ by readme-md-generator
