Skip to content

Commit

Permalink
graphql heartbeat endpoint. #423
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 22, 2020
1 parent 8c80566 commit f00f1c4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
7 changes: 4 additions & 3 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4276,7 +4276,7 @@ type PublicationSoftwareConnectionWithMeta {
type Query {
_service: _Service!
audiovisual(id: ID!): Audiovisual!
audiovisuals(first: Int = 25, query: String): [Audiovisual!]!
audiovisuals(first: Int = 25, hasCitations: Int, hasDownloads: Int, hasViews: Int, query: String): [Audiovisual!]!
client(id: ID!): Client!
clients(
"""
Expand Down Expand Up @@ -4388,10 +4388,11 @@ type Query {
last: Int
query: String
): FunderConnectionWithMeta!
heartbeat: String!
image(id: ID!): Image!
images(first: Int = 25, query: String): [Image!]!
interactiveResource(id: ID!): InteractiveResource!
interactiveResources(first: Int = 25, query: String): [InteractiveResource!]!
interactiveResources(first: Int = 25, hasCitations: Int, hasDownloads: Int, hasViews: Int, query: String): [InteractiveResource!]!
model(id: ID!): Model!
models(first: Int = 25, query: String): [Model!]!
organization(id: ID!): Organization!
Expand Down Expand Up @@ -4435,7 +4436,7 @@ type Query {
): PersonConnectionWithMeta!
person(id: ID!): Person
physicalObject(id: ID!): PhysicalObject!
physicalObjects(first: Int = 25, query: String): [PhysicalObject!]!
physicalObjects(first: Int = 25, hasCitations: Int, hasDownloads: Int, hasViews: Int, query: String): [PhysicalObject!]!
prefix(id: ID!): Prefix!
prefixes(first: Int = 25, query: String): [Prefix!]!
provider(id: ID!): Provider!
Expand Down
12 changes: 10 additions & 2 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
class QueryType < BaseObject
extend_type

field :heartbeat, String, null: false do
end

def heartbeat
heartbeat = Heartbeat.new
heartbeat.string
end

field :providers, ProviderConnectionWithMetaType, null: false, connection: true, max_page_size: 1000 do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
Expand Down Expand Up @@ -345,8 +353,8 @@ def model(id:)
argument :first, Int, required: false, default_value: 25
end

def physical_objects(query: nil, has_citations: has_citations, has_views: has_views, has_downloads: has_downloads, first: nil)
Doi.query(query, resource_type_id: "PhysicalObject", state: "findable", has_citations: nil, has_views: nil, has_downloads: nil, page: { number: 1, size: first }).results.to_a
def physical_objects(query: nil, has_citations: nil, has_views: nil, has_downloads: nil, first: nil)
Doi.query(query, resource_type_id: "PhysicalObject", state: "findable", has_citations: has_citations, has_views: has_views, has_downloads: has_downloads, page: { number: 1, size: first }).results.to_a
end

field :physical_object, PhysicalObjectType, null: false do
Expand Down
14 changes: 14 additions & 0 deletions spec/graphql/types/query_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,18 @@
expect(response.dig("data", "datasets", "nodes", 0, "references").first).to eq("id"=>"https://handle.test.datacite.org/#{target_doi.doi.downcase}", "publicationYear"=>2011)
end
end

describe "heartbeat" do
let(:query) do
%(query {
heartbeat
})
end

it "returns the heartbeat" do
response = LupoSchema.execute(query).as_json

expect(response.dig("data", "heartbeat")).to eq("OK")
end
end
end

0 comments on commit f00f1c4

Please sign in to comment.