Skip to content

πŸ™ GraphQL server implementation to expose stack overflow data dumps (Posts, Users, Comments, etc) powered by Go

License

Notifications You must be signed in to change notification settings

snimmagadda1/stack-exchange-graphql-server

Repository files navigation

Welcome to stack-exchange-graphql-server

Version Build Status Go Report License: MIT

A GraphQL implementation to expose stack overflow resources efficiently (Comments, Posts, Answers, Votes, etc)

Stack Exchange doesn't have a GraphQL endpoint so I made one. The live API above is in POC mode for now as the schema is built. It is currently serving content from https://health.stackexchange.com/ and is updated weekly with more to come as the pipeline & infra are beefed up & built out. 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.

Usage

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 the highest scoring Q&A pages in a sub-community:

query postsPagination {
  allPostsCursor(first: 10, where: { order: { field: votes, order: DESC } }) {
   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.go

Some 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...

Compile

go build cmd/server.go

Development

Options for development are readily flexible with more streamlined routes to come... For now the following is available:

  1. 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
    
  2. ~1K rows exist here will be used as inserts to your schema.

  3. Create (or copy) a .env file with the variables in the table above set to configure the local GraphQL server.

  4. Start the server:

go run cmd/server.go

Run tests

TODO

Built with

Current data pipeline

I'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. Diagram of current processing pipeline

Author

πŸ‘€ Sai Nimmagadda

🀝 Contributing

This project is currently in build-mode. Contributions, issues and feature requests are welcome!

Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

πŸ“ License

Copyright Β© 2020 Sai Nimmagadda.

This project is MIT licensed.


This README was generated with ❀️ by readme-md-generator