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.
- OR -
- Ruby 2.7.2
- Rails 5.2.6
- Fork and clone this repo
- Bundle install
- Configure cors.rb with your specified allowable origins, methods, headers, and max_age
- Configure Google Cloud storage (see details below)
rails db:{create,migrate,seed}
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
Visit our Wiki for more information on endpoints available, along with sample requests and responses.
Run tests on mutations and queries using the GraphIQL interface:
- Run your dev server:
rails s
- 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