Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
cassiascheffer committed Oct 8, 2024
1 parent 281fff9 commit 8d0c2bc
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GraphQL Hive: `graphql-ruby` integration
# GraphQL Hive: `graphql-ruby` integration
[![CI Suite](https://github.com/charlypoly/graphql-ruby-hive/actions/workflows/ci.yml/badge.svg)](https://github.com/charlypoly/graphql-ruby-hive/actions)
[![Gem Version](https://badge.fury.io/rb/graphql-hive.svg)](https://rubygems.org/gems/graphql-hive)

Expand Down Expand Up @@ -64,15 +64,30 @@ If you only want to use the operations monitoring, replace the `reporting` optio

<br/>

## 3. (Optional) Configure Lifecycle Hooks
## 3. Configure Lifecycle Hooks

Calling these hooks are situational - it's likely that you may not need to call
them at all!
### Starting and Stopping the Usage Reporter

### `on_start`
Call `GraphQL::Hive.instance.on_start` and `GraphQL::Hive.instance.on_exit` when starting and stopping your GraphQL API.

Call this hook if you are running `GraphQL::Hive` in a process that `fork`s
itself.
For example in the `puma` web server running in default mode you can add the following hooks:
```rb
# config/puma.rb
on_booted do
# Start the Hive client when the server is booted or rebooted
GraphQL::Hive.instance.on_start
end

on_restart do
# Exit the Hive client when the server is restarted
GraphQL::Hive.instance.on_exit
end

on_stopped do
# Exit the Hive client when the server is stopped
GraphQL::Hive.instance.on_exit
end
```

example: `puma` web server running in (["clustered
mode"](https://github.com/puma/puma/tree/6d8b728b42a61bcf3c1e4c698c9165a45e6071e8#clustered-mode))
Expand All @@ -84,17 +99,6 @@ preload_app!
on_worker_boot do
GraphQL::Hive.instance.on_start
end
```

### `on_exit`

If your GraphQL API process is shut down non-gracefully but has a shutdown hook
to call into, call `on_worker_exit`.

`puma` example:

```ruby
# config/puma.rb

on_worker_shutdown do
GraphQL::Hive.instance.on_exit
Expand Down Expand Up @@ -154,12 +158,12 @@ class MySchema < GraphQL::Schema
debug: false, # verbose logs
logger: MyLogger.new,
endpoint: 'app.graphql-hive.com',
port: 80,
port: 80,
buffer_size: 50, # forward the operations data to Hive every 50 requests

collect_usage: true, # report usage to Hive
collect_usage_sampling: {
# optional members of `collect_usage_sampling`
# optional members of `collect_usage_sampling`
sample_rate: 0.5, # % of operations reported
sampler: proc { |context| context.operation_name.includes?('someQuery') 1 : 0.5 }, # assign custom sampling rates (overrides `sampling rate`)
at_least_once: true, # sample every distinct operation at least once
Expand All @@ -168,11 +172,11 @@ class MySchema < GraphQL::Schema

report_schema: true, # publish schema to Hive
# mandatory if `report_schema: true`
reporting: {
reporting: {
# mandatory members of `reporting`
author: 'Author of the latest change',
commit: 'git sha or any identifier',
# optional members of `reporting
# optional members of `reporting
service_name: '',
service_url: '',
},
Expand Down

0 comments on commit 8d0c2bc

Please sign in to comment.