From 5e18a74ed4992f05586851cd49b9639f3e445dad Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Thu, 10 Oct 2019 07:10:14 +0200 Subject: [PATCH] fields type, sourceId and targetid for graphql. #346 --- Gemfile | 1 + Gemfile.lock | 63 ++++++++++++----------- app/graphql/types/doi_item.rb | 5 ++ app/graphql/types/event_data_edge.rb | 8 +++ app/graphql/types/event_data_edge_type.rb | 6 ++- app/graphql/types/organization_type.rb | 7 ++- 6 files changed, 56 insertions(+), 34 deletions(-) diff --git a/Gemfile b/Gemfile index 024ecbf23..bda75fbbc 100644 --- a/Gemfile +++ b/Gemfile @@ -64,6 +64,7 @@ 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 'sprockets', '~> 3.7', '>= 3.7.2' group :development, :test do gem 'rspec-rails', '~> 3.8', '>= 3.8.2' diff --git a/Gemfile.lock b/Gemfile.lock index 8fbb5d432..e29a93f60 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -67,7 +67,7 @@ GEM audited (4.9.0) activerecord (>= 4.2, < 6.1) aws-eventstream (1.0.3) - aws-partitions (1.220.0) + aws-partitions (1.221.0) aws-sdk-core (3.68.1) aws-eventstream (~> 1.0, >= 1.0.2) aws-partitions (~> 1.0) @@ -210,7 +210,7 @@ GEM equivalent-xml (0.6.0) nokogiri (>= 1.4.3) erubi (1.9.0) - excon (0.62.0) + excon (0.67.0) facets (3.1.0) factory_bot (4.11.1) activesupport (>= 3.0.0) @@ -219,15 +219,15 @@ GEM railties (>= 3.0.0) faker (1.9.6) i18n (>= 0.7) - faraday (0.14.0) + faraday (0.17.0) multipart-post (>= 1.2, < 3) faraday-encoding (0.0.5) faraday - faraday_middleware (0.12.2) + faraday_middleware (0.13.1) faraday (>= 0.7.4, < 1.0) - faraday_middleware-aws-sigv4 (0.2.5) + faraday_middleware-aws-sigv4 (0.2.4) aws-sigv4 (~> 1.0) - faraday (>= 0.9, < 0.15) + faraday (>= 0.9) fast_jsonapi (1.5) activesupport (>= 4.2) ffi (1.11.1) @@ -241,7 +241,7 @@ GEM globalid (0.4.2) activesupport (>= 4.2.0) google-protobuf (3.10.0.rc.1) - graphql (1.9.12) + graphql (1.9.13) graphql-batch (0.4.1) graphql (>= 1.3, < 2) promise.rb (~> 0.7.2) @@ -311,21 +311,21 @@ GEM rest-client (~> 2.0.2) marcel (0.3.3) mimemagic (~> 0.3.2) - maremma (4.3) + maremma (4.4) activesupport (>= 4.2.5, < 6) addressable (>= 2.3.6) builder (~> 3.2, >= 3.2.2) - excon (~> 0.60, < 0.63) - faraday (~> 0.14, < 0.15) + excon (~> 0.67.0) + faraday (~> 0.17.0) faraday-encoding (~> 0.0.4) - faraday_middleware (~> 0.12.0) + faraday_middleware (~> 0.13.1) multi_json (~> 1.12) nokogiri (~> 1.10.4) oj (>= 2.8.3) method_source (0.9.2) mime-types (3.3) mime-types-data (~> 3.2015) - mime-types-data (3.2019.0904) + mime-types-data (3.2019.1009) mimemagic (0.3.3) mini_magick (4.9.5) mini_mime (1.0.2) @@ -345,7 +345,7 @@ GEM oj (2.18.5) oj_mimic_json (1.0.1) pandoc-ruby (2.0.2) - parallel (1.17.0) + parallel (1.18.0) parser (2.6.5.0) ast (~> 2.4.0) postrank-uri (1.0.24) @@ -385,8 +385,8 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.2.0) - loofah (~> 2.2, >= 2.2.2) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) railties (5.2.3) actionpack (= 5.2.3) activesupport (= 5.2.3) @@ -426,31 +426,31 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) rspec-benchmark (0.4.0) benchmark-perf (~> 0.4.0) benchmark-trend (~> 0.2.0) rspec (>= 3.0.0, < 4.0.0) - rspec-core (3.8.2) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.5) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.2) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-rails (3.8.2) + rspec-support (~> 3.9.0) + rspec-rails (3.9.0) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.3) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.0) rubocop (0.68.1) jaro_winkler (~> 1.5.1) parallel (~> 1.10) @@ -615,6 +615,7 @@ DEPENDENCIES spring spring-commands-rspec spring-watcher-listen (~> 2.0.0) + sprockets (~> 3.7, >= 3.7.2) string_pattern strip_attributes (~> 1.8) turnout (~> 2.5) diff --git a/app/graphql/types/doi_item.rb b/app/graphql/types/doi_item.rb index 246164894..3b4b60f9f 100644 --- a/app/graphql/types/doi_item.rb +++ b/app/graphql/types/doi_item.rb @@ -6,6 +6,7 @@ module DoiItem description "Information about DOIs" field :id, ID, null: false, hash_key: "identifier", description: "The persistent identifier for the resource" + field :type, String, null: false, description: "The type of the item." field :creators, [PersonType], null: true, description: "The main researchers involved in producing the data, or the authors of the publication, in priority order" do argument :first, Int, required: false, default_value: 20 end @@ -33,6 +34,10 @@ module DoiItem field :client, ClientType, null: true, description: "The client account managing this resource" field :provider, ProviderType, null: true, description: "The provider account managing this resource" + def type + object.types["schema_org"] + end + def creators(first: nil) Array.wrap(object.creators[0...first]).map do |c| Hashie::Mash.new( diff --git a/app/graphql/types/event_data_edge.rb b/app/graphql/types/event_data_edge.rb index 8aa87598c..3d44e89c8 100644 --- a/app/graphql/types/event_data_edge.rb +++ b/app/graphql/types/event_data_edge.rb @@ -14,6 +14,14 @@ def event_data end end + def source_id + self.node[:id] + end + + def target_id + self.parent[:id] + end + def source event_data[:source_id].underscore.camelcase(:lower) end diff --git a/app/graphql/types/event_data_edge_type.rb b/app/graphql/types/event_data_edge_type.rb index 3f289dac0..734025813 100644 --- a/app/graphql/types/event_data_edge_type.rb +++ b/app/graphql/types/event_data_edge_type.rb @@ -3,7 +3,9 @@ class EventDataEdgeType < GraphQL::Types::Relay::BaseEdge node_type(EventDataType) + field :source_id, String, null: false, description: "The source ID of the event." + field :target_id, String, null: false, description: "The target ID of the event." field :source, String, null: false, description: "Source for this event" - field :relation_type, String, null: false, description: "Relation type for this event" - field :total, Integer, null: false, description: "Total count for this event" + field :relation_type, String, null: false, description: "Relation type for this event." + field :total, Integer, null: false, description: "Total count for this event." end diff --git a/app/graphql/types/organization_type.rb b/app/graphql/types/organization_type.rb index f95f5f803..732c647e6 100644 --- a/app/graphql/types/organization_type.rb +++ b/app/graphql/types/organization_type.rb @@ -3,7 +3,8 @@ class OrganizationType < BaseObject description "Information about organizations" - field :id, ID, null: true, description: "ROR ID" + field :id, ID, null: false, description: "ROR ID" + field :type, String, null: false, description: "The type of the item." field :name, String, null: false, description: "The name of the organization." field :alternate_name, [String], null: true, description: "An alias for the organization." field :identifier, [IdentifierType], null: true, description: "The identifier(s) for the organization." @@ -27,6 +28,10 @@ class OrganizationType < BaseObject # argument :first, Int, required: false, default_value: 25 # end + def type + "Organization" + end + def alternate_name object.aliases + object.acronyms end