Skip to content

Commit

Permalink
added fields_of_science field for graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 4, 2020
1 parent cc67a12 commit 29bd5c5
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 1 deletion.
145 changes: 145 additions & 0 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ type Audiovisual implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -430,6 +435,11 @@ type Book implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -657,6 +667,11 @@ type BookChapter implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -970,6 +985,11 @@ type Collection implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -1239,6 +1259,11 @@ type ConferencePaper implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -1709,6 +1734,11 @@ type DataPaper implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -1979,6 +2009,11 @@ type Dataset implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -2360,6 +2395,11 @@ type Dissertation implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -2634,6 +2674,11 @@ interface DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -2861,6 +2906,11 @@ type Event implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -3116,6 +3166,11 @@ type EventData implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -3367,6 +3422,21 @@ type Facet {
title: String
}

"""
Information about OECD Fields of Science
"""
type FieldOfScience {
"""
Fields of Science id
"""
id: ID

"""
Fields of Science name
"""
name: String
}

"""
Information about funders
"""
Expand Down Expand Up @@ -3643,6 +3713,11 @@ type Image implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -3913,6 +3988,11 @@ type Instrument implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -4182,6 +4262,11 @@ type InteractiveResource implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -4477,6 +4562,11 @@ type JournalArticle implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -4978,6 +5068,11 @@ type Model implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -5363,6 +5458,11 @@ type Other implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -5658,6 +5758,11 @@ type PeerReview implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -6044,6 +6149,11 @@ type PhysicalObject implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -6367,6 +6477,11 @@ type Preprint implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -6638,6 +6753,11 @@ type Publication implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -7351,6 +7471,11 @@ type Service implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -7623,6 +7748,11 @@ type Software implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -7925,6 +8055,11 @@ type Sound implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -8378,6 +8513,11 @@ type Work implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down Expand Up @@ -8650,6 +8790,11 @@ type Workflow implements DoiItem {
"""
downloadsOverTime: [YearMonthTotal!]

"""
OECD Fields of Science of the resource
"""
fieldsOfScience: [FieldOfScience!]

"""
Technical format of the resource
"""
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/types/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class BaseConnection < GraphQL::Types::Relay::BaseConnection
"cc-by-2.5" => "CC-BY-2.5",
"cc-by-3.0" => "CC-BY-3.0",
"cc-by-4.0" => "CC-BY-4.0",
"cc-by-nc-2.5" => "CC-BY-NC-2.5",
"cc-by-nc-3.0" => "CC-BY-NC-3.0",
"cc-by-nc-4.0" => "CC-BY-NC-4.0",
"cc-by-nc-nd-4.0" => "CC-BY-NC-ND-4.0",
"cc-by-nc-sa-4.0" => "CC-BY-NC-SA-4.0",
Expand Down
12 changes: 12 additions & 0 deletions app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module DoiItem
field :publication_year, Int, null: true, description: "The year when the data was or will be made publicly available"
field :publisher, String, null: true, description: "The name of the entity that holds, archives, publishes prints, distributes, releases, issues, or produces the resource"
field :subjects, [SubjectType], null: true, description: "Subject, keyword, classification code, or key phrase describing the resource"
field :fields_of_science, [FieldOfScienceType], null: true, description: "OECD Fields of Science of the resource"
field :dates, [DateType], null: true, description: "Different dates relevant to the work"
field :registered, GraphQL::Types::ISO8601DateTime, null: true, description: "DOI registration date"
field :language, LanguageType, null: true, description: "The primary language of the resource"
Expand Down Expand Up @@ -216,6 +217,17 @@ def registration_agency
}.compact
end

def fields_of_science
Array.wrap(object.subjects)
.select { |s| s.subjectScheme == "Fields of Science and Technology (FOS)" }
.map do |s|
name = s.subject.gsub("FOS: ", "")
{
"id" => name.parameterize(separator: '_'),
"name" => name }
end
end

def creators(**args)
Array.wrap(object.creators[0...args[:first]]).map do |c|
Hashie::Mash.new(
Expand Down
8 changes: 8 additions & 0 deletions app/graphql/types/field_of_science_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class FieldOfScienceType < BaseObject
description "Information about OECD Fields of Science"

field :id, ID, null: true, description: "Fields of Science id"
field :name, String, null: true, description: "Fields of Science name"
end
5 changes: 5 additions & 0 deletions spec/graphql/types/dataset_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@
}
nodes {
id
fieldsOfScience {
id
name
}
}
}
})
Expand All @@ -177,6 +181,7 @@
expect(response.dig("data", "datasets", "pageInfo", "hasNextPage")).to be false
expect(response.dig("data", "datasets", "nodes").length).to eq(1)
expect(response.dig("data", "datasets", "nodes", 0, "id")).to eq(dataset.identifier)
expect(response.dig("data", "datasets", "nodes", 0, "fieldsOfScience")).to eq([{"id"=>"computer_and_information_sciences", "name"=>"Computer and information sciences"}])
end
end

Expand Down
Loading

0 comments on commit 29bd5c5

Please sign in to comment.