Skip to content

A GraphQL API built in Ruby/Rails using ActiveStorage for image uploading to Google Cloud Storage.

Notifications You must be signed in to change notification settings

hivemindapp/hivemind-backend

Repository files navigation

hivemind-bee-logo

HiveMind Backend

HiveMind is where beekeepers go to get advice, ask questions to the experts, and meet our community of "bee-lievers." The HiveMind backend is a GraphQL API built in Ruby and Ruby on Rails and leverages ActiveStorage for image uploading along with an integration to Google Cloud Storage.

Build Status

Check out the deployed app

  • OR -

Explore the frontend repo

System Dependencies

  • Ruby 2.7.2
  • Rails 5.2.6

Important Gems

Configuration

  1. Fork and clone this repo
  2. Bundle install
  3. Configure cors.rb with your specified allowable origins, methods, headers, and max_age
  4. Configure Google Cloud storage (see details below)
  5. rails db:{create,migrate,seed}

Google Cloud Storage Configuration

This app is currently configured to use GCS for both the development and production (staging) environments, while it uses local disk storage for testing. This is set in the storage.yml file, but requires a substantial amount of external configuration for security purposes. You will need:

  • A GCS account with a project and bucket
  • A service account and the key info provided for that, stored in a json file (but not checked into your git history). The GCS config instructions found here should get you what you need for this app. We recommend following the config for rails credentials, which the article lists as optional.
  • A separate CORS config for your cloud project, which will require you to set up gsutil (instructions here for gsutil quickstart). Once you have gsutil and have selected your project according to the setup instructions, create a json file that will look something like this (slightly edited here):
[
  {
    "origin": ["http://localhost:3000", "(backend prod url)", "(frontend app)"],
    "method": ["POST", "OPTIONS"], 
    "responseHeader": ["Origin", "content-type", "Content-Type", "Content-MD5", "Content-Disposition"],
    "maxAgeSeconds": 3600
  }
]

Then run this command in your root dir or where you've set up gsutil:

$ gsutil cors set full_path/to/cors_config/file.json gs://your-bucket-name

To view the config currently on your bucket:

$ gsutil cors get gs://your-bucket-name

Endpoints

Visit our Wiki for more information on endpoints available, along with sample requests and responses.

Database Schema

hivemind-database-diagram

Testing

Run tests on mutations and queries using the GraphIQL interface:

  1. Run your dev server: rails s
  2. Visit http:localhost:3000/graphiql

To run the full test suite, simply run bundle exec rspec. Gems required for testing:

  • 'database_cleaner' # DB cleaning between test runs
  • 'factory_bot_rails' # Creating mock data "factories"
  • 'faker' # Generating fake data for our mocks
  • 'rspec-graphql_matchers' # Provides matchers for GraphQL query/mutation testing
  • 'shoulda-matchers' # Allows for simpler and more elegant expect statements

Contributors

Backend Team

Frontend Team

About

A GraphQL API built in Ruby/Rails using ActiveStorage for image uploading to Google Cloud Storage.

Topics

Resources

Stars

Watchers

Forks

Languages