The stats service has a GraphQL API, https://graphql.org/ which differs to RESTful APIs.
There is only one endpoint path for this API /graphql
and it only supports the POST
HTTP method for the application/json
content type.
Introspect the available operations
curl -d '{"query": "{__schema {queryType {name fields {name}}mutationType {name fields {name}}}}"}' -H "Content-Type: application/json" -X POST https://graphql-stats.zooniverse.org/graphql
Event type counts per interval
Retrieve the number of classifications for a specified event type for a known interval. Non-required attributes are projectID
and userId
to filter the results.
Note: If you supply the the userId attribute you must provide a bearer token in the Authorization header, e.g.
Authorization: Bearer <TOKEN>
You must supply and eventType
, interval
and window
. Valid intervals are postgres intervals, e.g. 2 Days
, 24 Hours
, 60 Seconds
Valid windows are postgres intervals, e.g. 7 Days
, 2 Weeks
, 1 Month
, 1 Year
.
{
statsCount(
eventType: "classification",
interval: "1 Day",
window: "1 week",
projectId: "${project.id}",
userId: "${user.id}"
){
period,
count
}
}
Note: classification
events are currently the only supported event types.
-
Clone the repository
git clone https://github.com/zooniverse/zoo_stats_api_graphql
. -
Install Docker from the appropriate link above.
-
cd
into the cloned folder. -
Run
docker-compose build
to build the containers Panoptes API container. You will need to re-run this command on any changes toDockerfile.dev
(note the dev dockerfile, production isDockerfile
) -
Create and run the application containers with
docker-compose up
-
If the above step reports a missing database error, kill the docker-compose process or open a new terminal window in the current directory and then run
docker-compose run --rm zoo_stats bundle exec rake db:setup
to setup the database. This command will launch a new Docker container, run the rake DB setup task, and then clean up the container. -
Open up the application in your browser at http://localhost:3000
Once all the above steps complete you will have a working copy of the checked out code base. Keep your code up to date and rebuild the image on any code or configuration changes.
Note: You will need to re-install the gem dependencies for the application if you modify the Gemfile
* Run: docker-compose run --rm zoo_stats bundle install
-
Setup the test environment and database
- Run:
docker-compose run --rm -e RAILS_ENV=test zoo_stats bundle exec rake db:setup
- Run:
-
Run the tests
- Run:
docker-compose run -T --rm -e RAILS_ENV=test zoo_stats bundle exec rspec
- Run:
-
Get a console to interactively run / debug tests
- Run:
docker-compose run --rm -e RAILS_ENV=test zoo_stats bash
- Then in the container run:
bundle exec rspec
- Run:
-
Docker
This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com.