Skip to content

Commit

Permalink
fields type, sourceId and targetid for graphql. #346
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 10, 2019
1 parent 59ad0c0 commit 5e18a74
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 34 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
63 changes: 32 additions & 31 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions app/graphql/types/event_data_edge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions app/graphql/types/event_data_edge_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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
Expand Down

0 comments on commit 5e18a74

Please sign in to comment.