From 8d0c2bcc1c1af445d31d6a71bae861cbe9c7a44b Mon Sep 17 00:00:00 2001 From: Cassidy Scheffer Date: Tue, 8 Oct 2024 15:50:25 -0400 Subject: [PATCH] update readme --- README.md | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 9e3433c..c15aba8 100644 --- a/README.md +++ b/README.md @@ -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) @@ -64,15 +64,30 @@ If you only want to use the operations monitoring, replace the `reporting` optio
-## 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)) @@ -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 @@ -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 @@ -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: '', },