Skip to content

Commit

Permalink
Merge branch 'master' into stats_portal_improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner authored May 14, 2020
2 parents 8ad1cc6 + 37bc1eb commit 4333990
Show file tree
Hide file tree
Showing 30 changed files with 1,039 additions and 119 deletions.
5 changes: 2 additions & 3 deletions app/graphql/lupo_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ class LupoSchema < GraphQL::Schema

use GraphQL::Tracing::DataDogTracing, service: 'graphql'
use ApolloFederation::Tracing
use GraphQL::Batch
use GraphQL::Cache

default_max_page_size 1000
max_depth 10

# mutation(Types::MutationType)
query(QueryType)

use GraphQL::Batch
use GraphQL::Cache
end

GraphQL::Errors.configure(LupoSchema) do
Expand Down
130 changes: 107 additions & 23 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
"""
The connection type for ActorItem.
"""
type ActorConnection {
"""
A list of edges.
"""
edges: [ActorEdge]

"""
A list of nodes.
"""
nodes: [ActorItem]

"""
Information to aid in pagination.
"""
pageInfo: PageInfo!
totalCount: Int!
}

"""
An edge in a connection.
"""
type ActorEdge {
"""
A cursor for use in pagination.
"""
cursor: String!

"""
The item at the end of the edge.
"""
node: ActorItem
}

"""
Information about people, research organizations and funders
"""
interface ActorItem {
"""
An alias for the actor.
"""
alternateName: [String!]

"""
The persistent identifier for the actor.
"""
id: ID!

"""
The name of the actor.
"""
name: String!

"""
The type of the actor.
"""
type: String!
}

"""
Information about addresses
"""
Expand Down Expand Up @@ -5260,14 +5321,14 @@ type Facet {
"""
Information about funders
"""
type Funder {
type Funder implements ActorItem {
"""
Physical address of the funder.
"""
address: Address

"""
An alias for the funder.
An alias for the actor.
"""
alternateName: [String!]

Expand Down Expand Up @@ -5315,12 +5376,12 @@ type Funder {
downloadCount: Int

"""
Crossref Funder ID
The persistent identifier for the actor.
"""
id: ID!

"""
The name of the funder.
The name of the actor.
"""
name: String!

Expand Down Expand Up @@ -5391,7 +5452,7 @@ type Funder {
): SoftwareConnection

"""
The type of the item.
The type of the actor.
"""
type: String!

Expand Down Expand Up @@ -8155,14 +8216,14 @@ type ModelEdge {
"""
Information about organizations
"""
type Organization {
type Organization implements ActorItem {
"""
Physical address of the organization.
"""
address: Address

"""
An alias for the organization.
An alias for the actor.
"""
alternateName: [String!]

Expand Down Expand Up @@ -8209,17 +8270,17 @@ type Organization {
downloadCount: Int

"""
ROR ID
The persistent identifier for the actor.
"""
id: ID
id: ID!

"""
The identifier(s) for the organization.
"""
identifiers: [Identifier!]

"""
The name of the organization.
The name of the actor.
"""
name: String!

Expand Down Expand Up @@ -8288,14 +8349,14 @@ type Organization {
): SoftwareConnection

"""
The type of the item.
The type of the actor.
"""
type: String!

"""
URL of the organization.
"""
url: [String!]
url: [Url!]

"""
The number of views according to the Counter Code of Practice.
Expand Down Expand Up @@ -9290,12 +9351,17 @@ type PeerReviewEdge {
"""
A person.
"""
type Person {
type Person implements ActorItem {
"""
Affiliations(s) of the person.
"""
affiliation: [Affiliation!]

"""
An alias for the actor.
"""
alternateName: [String!]

"""
The number of citations.
"""
Expand Down Expand Up @@ -9349,19 +9415,14 @@ type Person {
givenName: String

"""
The ORCID ID of the person.
"""
id: ID

"""
The name of the person.
The persistent identifier for the actor.
"""
name: String
id: ID!

"""
Other names.
The name of the actor.
"""
otherNames: [String!]
name: String!

"""
Authored publications
Expand Down Expand Up @@ -9428,7 +9489,7 @@ type Person {
): SoftwareConnection

"""
The type of the item.
The type of the actor.
"""
type: String!

Expand Down Expand Up @@ -10909,6 +10970,29 @@ type PublicationEdge {

type Query {
_service: _Service!
actor(id: ID!): ActorItem!
actors(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String

"""
Returns the elements in the list that come before the specified cursor.
"""
before: String

"""
Returns the first _n_ elements from the list.
"""
first: Int

"""
Returns the last _n_ elements from the list.
"""
last: Int
query: String
): ActorConnection!
audiovisual(id: ID!): Audiovisual!
audiovisuals(
"""
Expand Down
16 changes: 16 additions & 0 deletions app/graphql/types/actor_connection_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class ActorConnectionType < BaseConnection
edge_type(ActorEdgeType)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
args = object.arguments

Organization.query(args[:query], limit: 0).dig(:meta, "total").to_i +
Funder.query(args[:query], limit: 0).dig(:meta, "total").to_i +
Person.query(args[:query], limit: 0).dig(:meta, "total").to_i
end
end
5 changes: 5 additions & 0 deletions app/graphql/types/actor_edge_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class ActorEdgeType < GraphQL::Types::Relay::BaseEdge
node_type(ActorItem)
end
28 changes: 28 additions & 0 deletions app/graphql/types/actor_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module ActorItem
include BaseInterface
include Bolognese::MetadataUtils

description "Information about people, research organizations and funders"

field :id, ID, null: false, description: "The persistent identifier for the actor."
field :type, String, null: false, description: "The type of the actor."
field :name, String, null: false, description: "The name of the actor."
field :alternate_name, [String], null: true, description: "An alias for the actor."

definition_methods do
# Determine what object type to use for `object`
def resolve_type(object, context)
if object.type == "Person"
PersonType
elsif object.type == "Organization"
OrganizationType
elsif object.type == "Funder"
FunderType
else
raise "Unexpected Actor: #{object.inspect}"
end
end
end
end
6 changes: 5 additions & 1 deletion app/graphql/types/base_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ def doi_from_url(url)
def orcid_from_url(url)
if /\A(?:(http|https):\/\/(orcid.org)\/)(.+)\z/.match?(url)
uri = Addressable::URI.parse(url)
uri.path.gsub(/^\//, "").downcase
uri.path.gsub(/^\//, "").upcase
end
end

def ror_id_from_url(url)
Array(/\A(http|https):\/\/(ror\.org\/0\w{6}\d{2})\z/.match(url)).last
end

def facet_by_year(arr)
arr.map do |hsh|
{ "id" => hsh["key_as_string"][0..3],
Expand Down
6 changes: 2 additions & 4 deletions app/graphql/types/funder_type.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# frozen_string_literal: true

class FunderType < BaseObject
implements ActorItem

description "Information about funders"

field :id, ID, null: false, description: "Crossref Funder ID"
field :type, String, null: false, description: "The type of the item."
field :name, String, null: false, description: "The name of the funder."
field :alternate_name, [String], null: true, description: "An alias for the funder."
field :address, AddressType, null: true, description: "Physical address of the funder."
field :view_count, Integer, null: true, description: "The number of views according to the Counter Code of Practice."
field :download_count, Integer, null: true, description: "The number of downloads according to the Counter Code of Practice."
Expand Down
8 changes: 3 additions & 5 deletions app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# frozen_string_literal: true

class OrganizationType < BaseObject
implements ActorItem

description "Information about organizations"

field :id, ID, null: true, 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 :identifiers, [IdentifierType], null: true, description: "The identifier(s) for the organization."
field :url, [String], null: true, hash_key: "links", description: "URL of the organization."
field :url, [Url], null: true, hash_key: "links", description: "URL of the organization."
field :address, AddressType, null: true, description: "Physical address of the organization."
field :view_count, Integer, null: true, description: "The number of views according to the Counter Code of Practice."
field :download_count, Integer, null: true, description: "The number of downloads according to the Counter Code of Practice."
Expand Down
6 changes: 2 additions & 4 deletions app/graphql/types/person_type.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# frozen_string_literal: true

class PersonType < BaseObject
implements ActorItem

description "A person."

field :id, ID, null: true, description: "The ORCID ID of the person."
field :type, String, null: false, description: "The type of the item."
field :name, String, null: true, description: "The name of the person."
field :given_name, String, null: true, 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."
field :other_names, [String], null: true, description: "Other names."
field :affiliation, [AffiliationType], null: true, description: "Affiliations(s) of the person."
field :view_count, Integer, null: true, description: "The number of views according to the Counter Code of Practice."
field :download_count, Integer, null: true, description: "The number of downloads according to the Counter Code of Practice."
Expand Down
Loading

0 comments on commit 4333990

Please sign in to comment.