Skip to content

Commit

Permalink
added graphql tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 5, 2019
1 parent 76a2288 commit c7cef37
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 81 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ gem 'batch-loader', '~> 1.4', '>= 1.4.1'
gem 'graphql-cache', '~> 0.6.0', git: "https://github.com/stackshareio/graphql-cache"
gem 'apollo-federation', '~> 0.4.0'
gem 'google-protobuf', '3.10.0.rc.1'
# gem 'ddtrace', '~> 0.23.3'

group :development, :test do
gem 'rspec-rails', '~> 3.8', '>= 3.8.2'
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/graphql_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ def execute
query = params[:query]
operation_name = params[:operationName]
context = {
# Query context goes here, for example:
# current_user: current_user,
tracing_enabled: ApolloFederation::Tracing.should_add_traces(headers)
}
result = LupoSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
render json: MultiJson.dump(result)
render json: ApolloFederation::Tracing.attach_trace_to_result(result)
rescue => e
raise e unless Rails.env.development?
handle_error_in_development e
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/lupo_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class LupoSchema < GraphQL::Schema
include ApolloFederation::Schema

# use(GraphQL::Tracing::DataDogTracing, analytics_enabled: Rails.env.production?)
use ApolloFederation::Tracing

default_max_page_size 250
max_depth 10
Expand Down
33 changes: 17 additions & 16 deletions app/graphql/types/funder_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# frozen_string_literal: true

class FunderConnectionWithMetaType < BaseConnection
edge_type(FunderEdgeType)
field_class GraphQL::Cache::Field
# class FunderConnectionWithMetaType < BaseConnection

field :publication_connection_count, Integer, null: false, cache: true
field :dataset_connection_count, Integer, null: false, cache: true
field :software_connection_count, Integer, null: false, cache: true
# edge_type(FunderEdgeType)
# field_class GraphQL::Cache::Field

# field :publication_connection_count, Integer, null: false, cache: true
# field :dataset_connection_count, Integer, null: false, cache: true
# field :software_connection_count, Integer, null: false, cache: true

def publication_connection_count
Event.query(nil, citation_type: "Funder-ScholarlyArticle").results.total
end
# def publication_connection_count
# Event.query(nil, citation_type: "Funder-ScholarlyArticle").results.total
# end

def dataset_connection_count
Event.query(nil, citation_type: "Dataset-Funder").results.total
end
# def dataset_connection_count
# Event.query(nil, citation_type: "Dataset-Funder").results.total
# end

def software_connection_count
Event.query(nil, citation_type: "Funder-SoftwareSourceCode").results.total
end
end
# def software_connection_count
# Event.query(nil, citation_type: "Funder-SoftwareSourceCode").results.total
# end
# end
7 changes: 1 addition & 6 deletions app/graphql/types/funder_type.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class FunderType < BaseObject
description "Information about funders"
extend_type

field :datasets, FunderDatasetConnectionWithMetaType, null: false, description: "Funded datasets", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
Expand All @@ -16,11 +16,6 @@ class FunderType < BaseObject
argument :first, Int, required: false, default_value: 25
end

def address
{ "type" => "postalAddress",
"address_country" => object.country.to_h.fetch("name", nil) }
end

def datasets(**args)
ids = Event.query(nil, obj_id: object[:id], citation_type: "Dataset-Funder").results.to_a.map do |e|
doi_from_url(e.subj_id)
Expand Down
40 changes: 20 additions & 20 deletions app/graphql/types/person_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# frozen_string_literal: true

class PersonConnectionWithMetaType < BaseConnection
edge_type(PersonEdgeType)
field_class GraphQL::Cache::Field
# class PersonConnectionWithMetaType < BaseConnection
# edge_type(PersonEdgeType)
# field_class GraphQL::Cache::Field

field :publication_connection_count, Integer, null: false, cache: true
field :dataset_connection_count, Integer, null: false, cache: true
field :software_connection_count, Integer, null: false, cache: true
field :organization_connection_count, Integer, null: false, cache: true
# field :publication_connection_count, Integer, null: false, cache: true
# field :dataset_connection_count, Integer, null: false, cache: true
# field :software_connection_count, Integer, null: false, cache: true
# field :organization_connection_count, Integer, null: false, cache: true

def publication_connection_count
Event.query(nil, citation_type: "Person-ScholarlyArticle").results.total
end
# def publication_connection_count
# Event.query(nil, citation_type: "Person-ScholarlyArticle").results.total
# end

def dataset_connection_count
Event.query(nil, citation_type: "Dataset-Person").results.total
end
# def dataset_connection_count
# Event.query(nil, citation_type: "Dataset-Person").results.total
# end

def software_connection_count
Event.query(nil, citation_type: "Person-SoftwareSourceCode").results.total
end
# def software_connection_count
# Event.query(nil, citation_type: "Person-SoftwareSourceCode").results.total
# end

def organization_connection_count
Event.query(nil, citation_type: "Organization-Person").results.total
end
end
# def organization_connection_count
# Event.query(nil, citation_type: "Organization-Person").results.total
# end
# end
15 changes: 1 addition & 14 deletions app/graphql/types/person_type.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# frozen_string_literal: true

class PersonType < BaseObject
description "A person."

field :id, ID, null: true, description: "The ORCID ID of the person."
field :name, String, null: true, description: "The name of the person."
field :given_name, String, null: true, hash_key: "given_names", description: "Given name. In the U.S., the first name of a Person."
field :family_name, String, null: true, description: "Family name. In the U.S., the last name of an Person."
extend_type

field :datasets, PersonDatasetConnectionWithMetaType, null: true, description: "Authored datasets", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
Expand All @@ -20,14 +15,6 @@ class PersonType < BaseObject
argument :first, Int, required: false, default_value: 25
end

def id
object.uid ? "https://orcid.org/#{object.uid}" : object.id
end

def name
object.name
end

def datasets(**args)
ids = Event.query(nil, obj_id: https_to_http(object.uid || object.id), citation_type: "Dataset-Person").results.to_a.map do |e|
doi_from_url(e.subj_id)
Expand Down
20 changes: 0 additions & 20 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,6 @@ def prefix(id:)
Prefix.where(prefix: id).first
end

field :funders, FunderConnectionWithMetaType, null: false, connection: true, max_page_size: 100 do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end

def funders(query: nil, first: nil)
Funder.query(query, limit: first).fetch(:data, [])
end

field :funder, FunderType, null: false do
argument :id, ID, required: true
end

def funder(id:)
result = Funder.find_by_id(id).fetch(:data, []).first
fail ActiveRecord::RecordNotFound if result.nil?

result
end

field :organizations, OrganizationConnectionWithMetaType, null: false, connection: true, max_page_size: 100 do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
Expand Down

0 comments on commit c7cef37

Please sign in to comment.