Skip to content

Commit

Permalink
Merge pull request #917 from rmosolgo/tracing
Browse files Browse the repository at this point in the history
Add GraphQL::Tracing
  • Loading branch information
Robert Mosolgo authored Aug 30, 2017
2 parents d5aa35d + 725697e commit c21d770
Show file tree
Hide file tree
Showing 63 changed files with 1,154 additions and 232 deletions.
24 changes: 13 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ before_install:
- gem install bundler

rvm:
- 2.1.0 # Lowest version officially supported by that gem
- 2.2.7
- 2.3.4
- 2.1.10 # Lowest version officially supported by the gem is 2.1
- 2.4.1
- jruby-9.1.9.0

Expand All @@ -24,16 +22,20 @@ before_script:
- psql -c 'create database graphql_ruby_test;' -U postgres

gemfile:
- gemfiles/rails_3.2.gemfile
- gemfiles/rails_4.1.gemfile
- gemfiles/rails_4.2.gemfile
- gemfiles/rails_5.0.gemfile
- gemfiles/rails_5.1.gemfile
- gemfiles/rails_3.2.gemfile
- gemfiles/rails_4.1.gemfile
- gemfiles/rails_4.2.gemfile
- gemfiles/rails_5.0.gemfile
- gemfiles/rails_5.1.gemfile


matrix:
include:
- env: DATABASE=POSTGRESQL
gemfile: Gemfile
gemfile: gemfiles/rails_5.1.gemfile
rvm: 2.4.1
- env: WITHOUT_RAILS=yes
gemfile: gemfiles/without_rails.gemfile
rvm: 2.4.1

exclude:
Expand All @@ -43,11 +45,11 @@ matrix:
gemfile: gemfiles/rails_4.1.gemfile
- rvm: 2.4.1
gemfile: gemfiles/rails_4.2.gemfile
- rvm: 2.1.0
- rvm: 2.1.10
gemfile: gemfiles/rails_5.0.gemfile # Rails 5 requires Ruby 2.2.2+
- rvm: jruby-9.1.9.0
gemfile: gemfiles/rails_5.0.gemfile # Rails 5 is not supported atm
- rvm: 2.1.0
- rvm: 2.1.10
gemfile: gemfiles/rails_5.1.gemfile # Rails 5 requires Ruby 2.2.2+
- rvm: jruby-9.1.9.0
gemfile: gemfiles/rails_5.1.gemfile # Rails 5 is not supported atm
8 changes: 8 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
# frozen_string_literal: true
appraise 'rails_3.2' do
gem "rails", "3.2.22.5"
gem 'activerecord', '~> 3.2.21'
gem 'actionpack', '~> 3.2.21'
gem 'test-unit'
end

appraise 'rails_4.1' do
gem "rails", "~> 4.1"
gem 'activerecord', '~> 4.1.10'
gem 'actionpack', '~> 4.1.10'
gem 'test-unit'
end

appraise 'rails_4.2' do
gem "rails", "~> 4.2"
gem 'activerecord', '~> 4.2.4'
gem 'actionpack', '~> 4.2.4'
gem 'concurrent-ruby', '1.0.0'
end

appraise 'rails_5.0' do
gem "rails", "~> 5.0"
gem 'activerecord', '~> 5.0.0'
gem 'actionpack', '~> 5.0.0'
end

appraise 'rails_5.1' do
gem 'rails', '~> 5.1.0.rc2'
end

appraise 'without_rails' do

end
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@

### Bug fixes

## 1.6.7 (11 Aug 2017)

### New features

- Add `GraphQL.parse_file` and `AbstractNode#filename` #873
- Support `.graphql` filepaths with `Schema.from_definition` #872

### Bug fixes

- Fix variable usage inside non-null list #888
- Fix unqualified usage of ActiveRecord::Relation #885
- Fix `FieldsWillMerge` handling of equivalent input objects
- Fix to call `prepare:` on nested input types

## 1.6.6 (14 Jul 2017)

### New features
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
source "https://rubygems.org"
gemspec

gem 'rails'
gem 'ruby-prof', :platform => :ruby
gem 'sqlite3', :platform => :ruby
gem 'pg', :platform => :ruby
Expand Down
19 changes: 18 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,24 @@ require_relative "lib/graphql/rake_task/validate"

Rake::TestTask.new do |t|
t.libs << "spec" << "lib"
t.pattern = "spec/**/*_spec.rb"

if defined?(Rails)
t.pattern = "spec/**/*_spec.rb"
else
t.test_files = Dir['spec/**/*_spec.rb'].reject do |f|

f.end_with?('_generator_spec.rb') ||
f.end_with?('input_object_type_spec.rb') ||
f.end_with?('variables_spec.rb') ||
f.end_with?('relation_connection_spec.rb') ||
f.end_with?('node_spec.rb') ||
f.end_with?('connection_instrumentation_spec.rb') ||
f.end_with?('graphql/schema_spec.rb') ||
f.end_with?('graphql/tracing/active_support_notifications_tracing_spec.rb') ||
f.start_with?('spec/graphql/relay/')
end
end

t.warning = false
end

Expand Down
13 changes: 8 additions & 5 deletions gemfiles/rails_3.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

source "https://rubygems.org"

gem "ruby-prof", :platform => :ruby
gem "sqlite3", :platform => :ruby
gem "pg", :platform => :ruby
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
gem "rails", "3.2.22.5"
gem "ruby-prof", platform: :ruby
gem "sqlite3", platform: :ruby
gem "pg", platform: :ruby
gem "pry"
gem "pry-stack_explorer", platform: :ruby
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "activerecord", "~> 3.2.21"
gem "actionpack", "~> 3.2.21"
gem "test-unit"

gemspec :path => "../"
gemspec path: "../"
13 changes: 8 additions & 5 deletions gemfiles/rails_4.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

source "https://rubygems.org"

gem "ruby-prof", :platform => :ruby
gem "sqlite3", :platform => :ruby
gem "pg", :platform => :ruby
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
gem "rails", "~> 4.1"
gem "ruby-prof", platform: :ruby
gem "sqlite3", platform: :ruby
gem "pg", platform: :ruby
gem "pry"
gem "pry-stack_explorer", platform: :ruby
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "activerecord", "~> 4.1.10"
gem "actionpack", "~> 4.1.10"
gem "test-unit"

gemspec :path => "../"
gemspec path: "../"
13 changes: 8 additions & 5 deletions gemfiles/rails_4.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

source "https://rubygems.org"

gem "ruby-prof", :platform => :ruby
gem "sqlite3", :platform => :ruby
gem "pg", :platform => :ruby
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
gem "rails", "~> 4.2"
gem "ruby-prof", platform: :ruby
gem "sqlite3", platform: :ruby
gem "pg", platform: :ruby
gem "pry"
gem "pry-stack_explorer", platform: :ruby
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "activerecord", "~> 4.2.4"
gem "actionpack", "~> 4.2.4"
gem "concurrent-ruby", "1.0.0"

gemspec :path => "../"
gemspec path: "../"
13 changes: 8 additions & 5 deletions gemfiles/rails_5.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

source "https://rubygems.org"

gem "ruby-prof", :platform => :ruby
gem "sqlite3", :platform => :ruby
gem "pg", :platform => :ruby
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
gem "rails", "~> 5.0"
gem "ruby-prof", platform: :ruby
gem "sqlite3", platform: :ruby
gem "pg", platform: :ruby
gem "pry"
gem "pry-stack_explorer", platform: :ruby
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "activerecord", "~> 5.0.0"
gem "actionpack", "~> 5.0.0"

gemspec :path => "../"
gemspec path: "../"
14 changes: 8 additions & 6 deletions gemfiles/rails_5.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

source "https://rubygems.org"

gem "ruby-prof", :platform => :ruby
gem "sqlite3", :platform => :ruby
gem "pg", :platform => :ruby
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
gem "rails", "~> 5.1.0"
gem "rails", "~> 5.1.0.rc2"
gem "ruby-prof", platform: :ruby
gem "sqlite3", platform: :ruby
gem "pg", platform: :ruby
gem "pry"
gem "pry-stack_explorer", platform: :ruby
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby

gemspec :path => "../"
gemspec path: "../"
12 changes: 12 additions & 0 deletions gemfiles/without_rails.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "ruby-prof", platform: :ruby
gem "sqlite3", platform: :ruby
gem "pg", platform: :ruby
gem "pry"
gem "pry-stack_explorer", platform: :ruby
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby

gemspec path: "../"
1 change: 0 additions & 1 deletion graphql.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Gem::Specification.new do |s|
s.add_development_dependency "minitest-focus", "~> 1.1"
s.add_development_dependency "minitest-reporters", "~>1.0"
s.add_development_dependency "racc", "~> 1.4"
s.add_development_dependency "rails"
s.add_development_dependency "rake", "~> 11"
s.add_development_dependency "rubocop", "~> 0.45"
# following are required for relay helpers
Expand Down
22 changes: 22 additions & 0 deletions guides/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,28 @@ bundle exec guard

When a file in `lib/` is modified, `guard` will run the corresponding file in `spec`. Guard also respects `# test_via:` comments, so it will run that test when the file changes (if there is no corresponding file by name).

### Gemfiles, Gemfiles, Gemfiles

`graphql-ruby` has several gemfiles to ensure support for various Rails versions.

You can run all gemfiles with

```
appraisal rake
```

You can specify a gemfile with `BUNDLE_GEMFILE`, eg:

```
BUNDLE_GEMFILE=gemfiles/rails_5.gemfile bundle exec rake
```

You can test without Rails using `WITHOUT_RAILS=yes`, eg:

```
WITHOUT_RAILS=yes bundle exec rake
```

### Debugging with Pry

[`pry`](http://pryrepl.org/) is included with GraphQL-Ruby's development setup to help with debugging.
Expand Down
2 changes: 1 addition & 1 deletion guides/fields/limits.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Always limit the number of items which can be returned from a list field. For ex
```ruby
field :items, types[ItemType] do
# Cap the number of items at 30
argument :limit, types.Int, default_value: 20, prepare: ->(limit) {[limit, 30].min}
argument :limit, types.Int, default_value: 20, prepare: ->(limit, ctx) {[limit, 30].min}
resolve ->(obj, args, ctx) {
obj.items.limit(args[:limit])
}
Expand Down
2 changes: 1 addition & 1 deletion guides/operation_store/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ The Authorization header takes the form:
"GraphQL::Pro #{client_name} #{hmac}"
```

[`graphql-pro-js`](http://github.com/rmosolgo/graphql-pro-js) adds this header to outgoing requests by using the provided `--client` and `--secret` values.
[`graphql-ruby-client`](http://github.com/rmosolgo/graphql-ruby-client) adds this header to outgoing requests by using the provided `--client` and `--secret` values.
10 changes: 5 additions & 5 deletions guides/operation_store/client_workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To use persisted queries with your client application, you must:
- [Sync operations](#syncing) from the client to the server
- [Send `params[:operationId]`](#client-usage) from the client app

This documentation also touches on [`graphql-pro-js`](https://github.com/rmosolgo/graphql-pro-js), a JavaScript client library for using `OperationStore`.
This documentation also touches on [`graphql-ruby-client`](https://github.com/rmosolgo/graphql-ruby-client), a JavaScript client library for using `OperationStore`.

### Add a Client

Expand All @@ -30,7 +30,7 @@ A default `secret` is provided for you, but you can also enter your own. The `se

Once a client is registered, it can push queries to the server via {% internal_link "the Sync API","/operation_store/getting_started#add-routes" %}.

The easiest way to sync is with `graphql-pro sync`, a command-line tool written in JavaScript: [`graphql-pro-js`](https://github.com/rmosolgo/graphql-pro-js).
The easiest way to sync is with `graphql-ruby-client sync`, a command-line tool written in JavaScript: [`graphql-ruby-client`](https://github.com/rmosolgo/graphql-ruby-client).

In short, it:

Expand All @@ -43,15 +43,15 @@ For example:

{{ "/operation_store/sync_example.png" | link_to_img:"OperationStore client sync" }}

See the readme for [Relay support](https://github.com/rmosolgo/graphql-pro-js#use-with-relay), [Apollo Client support](https://github.com/rmosolgo/graphql-pro-js#use-with-apollo-client), and [plain JS usage](https://github.com/rmosolgo/graphql-pro-js#use-with-plain-javascript).
See the readme for [Relay support](https://github.com/rmosolgo/graphql-ruby-client#use-with-relay), [Apollo Client support](https://github.com/rmosolgo/graphql-ruby-client#use-with-apollo-client), and [plain JS usage](https://github.com/rmosolgo/graphql-ruby-client#use-with-plain-javascript).



For help syncing in another language, you can take inspiration from the [JavaScript implementation](https://github.com/rmosolgo/graphql-pro-js), {% open_an_issue "Implementing operation sync in another language" %}, or email `[email protected]`.
For help syncing in another language, you can take inspiration from the [JavaScript implementation](https://github.com/rmosolgo/graphql-ruby-client), {% open_an_issue "Implementing operation sync in another language" %}, or email `[email protected]`.

### Client Usage

`graphql-pro-js` generates [Apollo middleware](https://github.com/rmosolgo/graphql-pro-js#use-with-apollo-client) and a [Relay helper function](https://github.com/rmosolgo/graphql-pro-js#use-with-relay) to get started quickly.
`graphql-ruby-client` generates [Apollo middleware](https://github.com/rmosolgo/graphql-ruby-client#use-with-apollo-client) and a [Relay helper function](https://github.com/rmosolgo/graphql-ruby-client#use-with-relay) to get started quickly.

To run stored operations from another client, send a param called `operationId` which is composed of:

Expand Down
Binary file modified guides/operation_store/sync_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions guides/queries/tracing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: Tracing
layout: guide
search: true
section: Queries
desc: Observation hooks for execution
index: 11
experimental: true
---

{{ "GraphQL::Tracing" | api_doc }} provides a `.trace` hook to observe events from the GraphQL runtime.

A tracer must implement `.trace`, for example:

```ruby
class MyCustomTracer
def trace(key, data)
# do stuff with key & data
yield
end
end
```

`.trace` is called with:

- `key`: the event happening in the runtime
- `data`: a hash of metadata about the event
- `&block`: the event itself, it must be `yield`ed and the value must be returned

To install a tracer, use `GraphQL::Tracing.install`:

```ruby
GraphQL::Tracing.install(MyCustomTracer.new)
```

To uninstall, use `GraphQL::Tracing.install(nil)`.

For a full list of events, see the {{ "GraphQL::Tracing" | api_doc }} API docs.
Loading

0 comments on commit c21d770

Please sign in to comment.