graphql-tracing 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 86eeee08cec50fcf2d935fd6ed9837b04eb718ec
4
+ data.tar.gz: 37aa1ad2c354d3c3a402116558a79b22c4f903dc
5
+ SHA512:
6
+ metadata.gz: 37a18ea8688bb312a6c07508a2745ec4c4d946a2909de3d1502f26c5fb883688ee245b04cf732dad85ddb1f43b1633b2006ed487e8222ab3d6c7b2c1d12e1e08
7
+ data.tar.gz: a3581be9dfdf320b86912e6760c073dea01c9b03018d8f322c739cedd363d7ca4bfd0d0360fa5a819744fee90bf6607c56f7696741b7f0be182b97a8c1a1e78d
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.4
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ script: bundle exec rspec
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at rsuh@uwaterloo.ca. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in graphql-tracing.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Reginald
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # GraphQL Tracing
2
+
3
+ [![Build Status](https://travis-ci.org/uniiverse/graphql-tracing.svg?branch=master)](https://travis-ci.org/uniiverse/graphql-tracing)
4
+
5
+ Ruby implementation of [GraphQL](https://github.com/rmosolgo/graphql-ruby) trace data in the [Apollo Tracing](https://github.com/apollographql/apollo-tracing) format.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'graphql-tracing'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install graphql-tracing
22
+
23
+ ## Usage
24
+
25
+ Define a GraphQL schema:
26
+
27
+ ```ruby
28
+ # Define a type
29
+ PostType = GraphQL::ObjectType.define do
30
+ name "Post"
31
+
32
+ field :id, !types.ID
33
+ field :title, !types.String
34
+ end
35
+
36
+ # Define a query
37
+ QueryType = GraphQL::ObjectType.define do
38
+ name "Query"
39
+
40
+ field :posts, !types[PostType] do
41
+ argument :user_id, !types.ID
42
+ resolve ->(obj, args, ctx) { Post.where(user_id: args[:user_id]) }
43
+ end
44
+ end
45
+
46
+ # Define a schema
47
+ Schema = GraphQL::Schema.define do
48
+ query QueryType
49
+ end
50
+
51
+ # Execute query
52
+ query = "query($user_id: ID!) {
53
+ posts(user_id: $user_id) {
54
+ id
55
+ title
56
+ }
57
+ }"
58
+ Schema.execute(query, variables: { user_id: 1 })
59
+ ```
60
+
61
+ ### Setup Tracing
62
+
63
+ Add 'GraphQL::Tracing' to your schema:
64
+
65
+ <pre>
66
+ Schema = GraphQL::Schema.define do
67
+ query QueryType
68
+ use GraphQL::Tracing.new
69
+ end
70
+ </pre>
71
+
72
+ Now your response should look something like:
73
+ ```
74
+ {
75
+ "data":{
76
+ "posts":[
77
+ {
78
+ "id":"1",
79
+ "title":"Post Title"
80
+ }
81
+ ]
82
+ },
83
+ "extensions":{
84
+ "tracing":{
85
+ "version":1,
86
+ "startTime":"2017-08-25T19:55:04.821Z",
87
+ "endTime":"2017-08-25T19:55:04.823Z",
88
+ "duration":1702785,
89
+ "execution":{
90
+ "resolvers":[
91
+ {
92
+ "path":[
93
+ "posts"
94
+ ],
95
+ "parentType":"Query",
96
+ "fieldName":"posts",
97
+ "returnType":"[Post!]!",
98
+ "startOffset":1451015,
99
+ "duration":15735
100
+ },
101
+ {
102
+ "path":[
103
+ "posts",
104
+ 0,
105
+ "id"
106
+ ],
107
+ "parentType":"Post",
108
+ "fieldName":"id",
109
+ "returnType":"ID!",
110
+ "startOffset":1556873,
111
+ "duration":6914
112
+ },
113
+ {
114
+ "path":[
115
+ "posts",
116
+ 0,
117
+ "title"
118
+ ],
119
+ "parentType":"Post",
120
+ "fieldName":"title",
121
+ "returnType":"String!",
122
+ "startOffset":1604795,
123
+ "duration":4053
124
+ },
125
+ {
126
+ "path":[
127
+ "posts",
128
+ 0,
129
+ "user_id"
130
+ ],
131
+ "parentType":"Post",
132
+ "fieldName":"user_id",
133
+ "returnType":"ID!",
134
+ "startOffset":1642942,
135
+ "duration":3814
136
+ }
137
+ ]
138
+ }
139
+ }
140
+ }
141
+ }
142
+ ```
143
+
144
+ ## Development
145
+
146
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
147
+
148
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
149
+
150
+ ## Contributing
151
+
152
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/graphql-tracing. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
153
+
154
+
155
+ ## License
156
+
157
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
158
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "graphql/tracing"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'graphql/tracing/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "graphql-tracing"
8
+ spec.version = Graphql::Tracing::VERSION
9
+ spec.authors = ["Reginald Suh", "Evgeny Li"]
10
+ spec.email = ["evgeny.li@universe.com", "rsuh@edu.uwaterloo.ca"]
11
+
12
+ spec.summary = %q{Ruby implementation of GraphQL trace data in the Apollo Tracing format.}
13
+ spec.description = %q{Ruby implementation of GraphQL trace data in the Apollo Tracing format.}
14
+ spec.homepage = "https://github.com/uniiverse/graphql-tracing"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.required_ruby_version = '>= 2.1.0' # keyword args
25
+
26
+ spec.add_runtime_dependency "graphql", ">= 1.6.0", "< 2"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.14"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency "pry"
32
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Graphql
4
+ module Tracing
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "graphql"
4
+ require "graphql/tracing/version"
5
+
6
+ module GraphQL
7
+ class Tracing
8
+ def use(schema_definition)
9
+ schema_definition.instrument(:query, self)
10
+ schema_definition.instrument(:field, self)
11
+ end
12
+
13
+ def before_query(query)
14
+ query.context['graphql-tracing'] = {
15
+ 'start_time' => Time.now.utc,
16
+ 'resolvers' => []
17
+ }
18
+ end
19
+
20
+ def after_query(query)
21
+ result = query.result
22
+ end_time = Time.now.utc
23
+ duration_nanos = duration_nanos(start_time: query.context['graphql-tracing']['start_time'], end_time: end_time)
24
+
25
+ result["extensions"] ||= {}
26
+ result["extensions"]["tracing"] = {
27
+ "version" => 1,
28
+ "startTime" => query.context['graphql-tracing']['start_time'].strftime('%FT%T.%3NZ'),
29
+ "endTime" => end_time.strftime('%FT%T.%3NZ'),
30
+ "duration" => duration_nanos,
31
+ "execution" => {
32
+ "resolvers" => query.context['graphql-tracing']['resolvers']
33
+ }
34
+ }
35
+ end
36
+
37
+ def instrument(type, field)
38
+ old_resolve_proc = field.resolve_proc
39
+
40
+ new_resolve_proc = ->(obj, args, ctx) do
41
+ resolve_start_time = Time.now.utc
42
+ result = old_resolve_proc.call(obj, args, ctx)
43
+ resolve_end_time = Time.now.utc
44
+
45
+ ctx['graphql-tracing']['resolvers'] << {
46
+ 'path' => ctx.path,
47
+ 'parentType' => type.name,
48
+ 'fieldName' => field.name,
49
+ 'returnType' => field.type.to_s,
50
+ 'startOffset' => duration_nanos(start_time: ctx['graphql-tracing']['start_time'], end_time: resolve_start_time),
51
+ 'duration' => duration_nanos(start_time: resolve_start_time, end_time: resolve_end_time)
52
+ }
53
+
54
+ result
55
+ end
56
+
57
+ field.redefine { resolve(new_resolve_proc) }
58
+ end
59
+
60
+ private
61
+
62
+ def duration_nanos(start_time:, end_time:)
63
+ ((end_time.to_f - start_time.to_f) * 1e9).to_i
64
+ end
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graphql-tracing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Reginald Suh
8
+ - Evgeny Li
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-08-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: graphql
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 1.6.0
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '2'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: 1.6.0
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: pry
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ description: Ruby implementation of GraphQL trace data in the Apollo Tracing format.
91
+ email:
92
+ - evgeny.li@universe.com
93
+ - rsuh@edu.uwaterloo.ca
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - ".gitignore"
99
+ - ".rspec"
100
+ - ".ruby-version"
101
+ - ".travis.yml"
102
+ - CODE_OF_CONDUCT.md
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - bin/console
108
+ - bin/setup
109
+ - graphql-tracing.gemspec
110
+ - lib/graphql/tracing.rb
111
+ - lib/graphql/tracing/version.rb
112
+ homepage: https://github.com/uniiverse/graphql-tracing
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 2.1.0
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.5.2
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Ruby implementation of GraphQL trace data in the Apollo Tracing format.
136
+ test_files: []