diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index d032dc7c1..7922314aa 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -6403,6 +6403,7 @@ type OrganizationConnectionWithTotal { personConnectionCount: Int! totalCount: Int! types: [Facet!] + years: [Facet!] } """ diff --git a/app/graphql/types/organization_connection_with_total_type.rb b/app/graphql/types/organization_connection_with_total_type.rb index 4e46f9694..4a306e9bb 100644 --- a/app/graphql/types/organization_connection_with_total_type.rb +++ b/app/graphql/types/organization_connection_with_total_type.rb @@ -4,11 +4,30 @@ class OrganizationConnectionWithTotalType < BaseConnection edge_type(OrganizationEdgeType) field_class GraphQL::Cache::Field + # data from GRID taken on Oct 18, 2020 https://grid.ac/downloads + # using latest release in any given year, starting with end of 2017, + # right before ROR was launched in January 2018 + YEARS = [ + { "id" => "2017", "title" => "2017", "count" => 80248 }, + { "id" => "2018", "title" => "2018", "count" => 11392 }, + { "id" => "2019", "title" => "2019", "count" => 6179 }, + ] + field :total_count, Integer, null: false, cache: true + field :years, [FacetType], null: true, cache: true field :types, [FacetType], null: true, cache: true field :countries, [FacetType], null: true, cache: true field :person_connection_count, Integer, null: false, cache: true + def years + count = YEARS.reduce(0) do |sum, i| + sum += i["count"] + sum + end + this_year = object.total_count > count ? { "id" => "2020", "title" => "2020", "count" => object.total_count - count } : nil + this_year ? YEARS << this_year : YEARS + end + def total_count object.total_count end diff --git a/spec/fixtures/vcr_cassettes/OrganizationType/query_all_organizations/returns_organization_information.yml b/spec/fixtures/vcr_cassettes/OrganizationType/query_all_organizations/returns_organization_information.yml new file mode 100644 index 000000000..7548c8284 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/OrganizationType/query_all_organizations/returns_organization_information.yml @@ -0,0 +1,120 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.ror.org/organizations?page=1 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.7.2; mailto:info@datacite.org) + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Content-Length: + - '11023' + Connection: + - keep-alive + Date: + - Sun, 18 Oct 2020 15:53:10 GMT + Status: + - 200 OK + X-Frame-Options: + - SAMEORIGIN + Allow: + - GET, HEAD, OPTIONS + X-Powered-By: + - Phusion Passenger 6.0.5 + Server: + - nginx/1.18.0 + Phusion Passenger 6.0.5 + Vary: + - Accept-Encoding,Cookie,Origin + X-Cache: + - Miss from cloudfront + Via: + - 1.1 d47fba004c254adb4e354d0cef499808.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - DUS51-C1 + X-Amz-Cf-Id: + - PnHPAkSYKd_YkrW0tENa0l62m4yuWpdursVJOD2whIHBZYQOAcyeGw== + body: + encoding: ASCII-8BIT + string: '{"number_of_results":98332,"time_taken":6,"items":[{"id":"https://ror.org/027bk5v43","name":"Illinois + Department of Public Health","types":["Government"],"links":["http://www.dph.illinois.gov/"],"aliases":[],"acronyms":["IDPH"],"status":"active","wikipedia_url":"https://en.wikipedia.org/wiki/Illinois_Department_of_Public_Health","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0004 0465 6701"]},"FundRef":{"preferred":null,"all":["100004888"]},"Wikidata":{"preferred":null,"all":["Q5999444"]},"GRID":{"preferred":"grid.280362.d","all":"grid.280362.d"}}},{"id":"https://ror.org/045rcvm30","name":"Kentucky + Cabinet For Health and Family Services","types":["Government"],"links":["http://chfs.ky.gov/"],"aliases":[],"acronyms":["CHFS"],"status":"active","wikipedia_url":"","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0004 0509 1749"]},"GRID":{"preferred":"grid.280376.8","all":"grid.280376.8"}}},{"id":"https://ror.org/04g7y4303","name":"Ernest + Gallo Clinic and Research Center","types":["Healthcare"],"links":["http://www.egcrc.org/"],"aliases":[],"acronyms":[],"status":"active","wikipedia_url":"","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0004 0633 1441"]},"GRID":{"preferred":"grid.280428.4","all":"grid.280428.4"}}},{"id":"https://ror.org/0258b0610","name":"Kansas + Department of Health and Environment","types":["Government"],"links":["http://www.kdheks.gov/"],"aliases":[],"acronyms":["KDHE"],"status":"active","wikipedia_url":"","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0004 0509 7737"]},"GRID":{"preferred":"grid.280429.5","all":"grid.280429.5"}}},{"id":"https://ror.org/006gvnw06","name":"North + Dakota Department of Health","types":["Government"],"links":["https://www.ndhealth.gov/"],"aliases":[],"acronyms":["NDDoH"],"status":"active","wikipedia_url":"","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0004 0376 9018"]},"GRID":{"preferred":"grid.280457.c","all":"grid.280457.c"}}},{"id":"https://ror.org/00g3xxn90","name":"Puerto + Rico Department of Health","types":["Government"],"links":["http://www.salud.gov.pr/Pages/default.aspx"],"aliases":[],"acronyms":[],"status":"active","wikipedia_url":"http://en.wikipedia.org/wiki/Puerto_Rico_Department_of_Health","labels":[{"label":"Departamento + de Salud de Puerto Rico","iso639":"es"}],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"OrgRef":{"preferred":null,"all":["29428249"]},"Wikidata":{"preferred":null,"all":["Q4294359"]},"GRID":{"preferred":"grid.280499.e","all":"grid.280499.e"}}},{"id":"https://ror.org/02ja0m249","name":"Rehabilitation + Institute of Chicago","types":["Healthcare"],"links":["http://www.ric.org/"],"aliases":[],"acronyms":["RIC"],"status":"active","wikipedia_url":"https://en.wikipedia.org/wiki/Rehabilitation_Institute_of_Chicago","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0004 0388 0584"]},"Wikidata":{"preferred":null,"all":["Q7309746"]},"GRID":{"preferred":"grid.280535.9","all":"grid.280535.9"}}},{"id":"https://ror.org/02f0bym65","name":"National + Opinion Research Center","types":["Nonprofit"],"links":["http://www.norc.org/Pages/default.aspx"],"aliases":[],"acronyms":["NORC"],"status":"active","wikipedia_url":"https://en.wikipedia.org/wiki/NORC_at_the_University_of_Chicago","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0000 8509 8393"]},"FundRef":{"preferred":null,"all":["100011073"]},"Wikidata":{"preferred":null,"all":["Q6974659"]},"GRID":{"preferred":"grid.280571.9","all":"grid.280571.9"}}},{"id":"https://ror.org/03s9ada67","name":"HealthPartners","types":["Nonprofit"],"links":["https://www.healthpartners.com/institute/index.html"],"aliases":[],"acronyms":[],"status":"active","wikipedia_url":"https://en.wikipedia.org/wiki/HealthPartners","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0004 0461 4886"]},"Wikidata":{"preferred":null,"all":["Q5690390"]},"GRID":{"preferred":"grid.280625.b","all":"grid.280625.b"}}},{"id":"https://ror.org/00190t495","name":"National + Center for Complementary and Integrative Health","types":["Facility"],"links":["https://nccih.nih.gov/"],"aliases":["National + Center for Complementary and Alternative Medicine","Office of Alternative + Medicine"],"acronyms":["NCCIH","NCCAM","OAM"],"status":"active","wikipedia_url":"https://en.wikipedia.org/wiki/National_Center_for_Complementary_and_Integrative_Health","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0000 8658 4190"]},"FundRef":{"preferred":"100008460","all":["100008460","100000064"]},"Wikidata":{"preferred":null,"all":["Q3278030"]},"GRID":{"preferred":"grid.280655.c","all":"grid.280655.c"}}},{"id":"https://ror.org/030g3hg75","name":"Lankenau + Institute for Medical Research","types":["Nonprofit"],"links":["http://www.limr.org/"],"aliases":[],"acronyms":["LIMR"],"status":"active","wikipedia_url":"https://en.wikipedia.org/wiki/Lankenau_Institute_for_Medical_Research","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0004 0422 4722"]},"OrgRef":{"preferred":null,"all":["8515209"]},"Wikidata":{"preferred":null,"all":["Q6487197"]},"GRID":{"preferred":"grid.280695.0","all":"grid.280695.0"}}},{"id":"https://ror.org/025chrz76","name":"Marshfield + Clinic","types":["Healthcare"],"links":["https://www.marshfieldclinic.org/"],"aliases":[],"acronyms":[],"status":"active","wikipedia_url":"https://en.wikipedia.org/wiki/Marshfield_Clinic","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0000 9274 7048"]},"Wikidata":{"preferred":null,"all":["Q17020389"]},"GRID":{"preferred":"grid.280718.4","all":"grid.280718.4"}}},{"id":"https://ror.org/00j899309","name":"Inflexxion","types":["Company"],"links":["http://www.inflexxion.com/"],"aliases":[],"acronyms":[],"status":"active","wikipedia_url":"","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0004 0400 1211"]},"GRID":{"preferred":"grid.280735.b","all":"grid.280735.b"}}},{"id":"https://ror.org/02qdbgx97","name":"Geisinger + Health System","types":["Healthcare"],"links":["http://www.geisinger.org/"],"aliases":[],"acronyms":["GHS"],"status":"active","wikipedia_url":"https://en.wikipedia.org/wiki/Geisinger_Health_System","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0004 0394 1447"]},"FundRef":{"preferred":null,"all":["100001126"]},"Wikidata":{"preferred":null,"all":["Q5530225"]},"GRID":{"preferred":"grid.280776.c","all":"grid.280776.c"}}},{"id":"https://ror.org/0242qs713","name":"Birmingham + VA Medical Center","types":["Healthcare"],"links":["http://www.va.gov/directory/guide/facility.asp?id=16"],"aliases":[],"acronyms":["BVAMC"],"status":"active","wikipedia_url":"","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0004 0419 1326"]},"GRID":{"preferred":"grid.280808.a","all":"grid.280808.a"}}},{"id":"https://ror.org/03x0d4x24","name":"Pacific + Northwest Diabetes Research Institute","types":["Nonprofit"],"links":["http://www.pnri.org/"],"aliases":[],"acronyms":["PNDRI"],"status":"active","wikipedia_url":"https://en.wikipedia.org/wiki/Pacific_Northwest_Diabetes_Research_Institute","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0000 9212 4713"]},"Wikidata":{"preferred":null,"all":["Q7122580"]},"GRID":{"preferred":"grid.280838.9","all":"grid.280838.9"}}},{"id":"https://ror.org/055ysan77","name":"Klein + Buendel","types":["Company"],"links":["http://www.kleinbuendel.com/"],"aliases":[],"acronyms":[],"status":"active","wikipedia_url":"","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0004 0546 4998"]},"GRID":{"preferred":"grid.280852.5","all":"grid.280852.5"}}},{"id":"https://ror.org/020hchp05","name":"Integrated + Laboratory Systems, Inc.","types":["Facility"],"links":["http://www.ils-inc.com/"],"aliases":["Rao + Enterprises, Inc"],"acronyms":["ILS"],"status":"active","wikipedia_url":"","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0004 0589 1113"]},"GRID":{"preferred":"grid.280855.2","all":"grid.280855.2"}}},{"id":"https://ror.org/020k7fn51","name":"Information + Management Services","types":["Company"],"links":["https://www.imsweb.com/"],"aliases":[],"acronyms":["IMS"],"status":"active","wikipedia_url":"","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"ISNI":{"preferred":null,"all":["0000 + 0000 9338 0647"]},"GRID":{"preferred":"grid.280929.8","all":"grid.280929.8"}}},{"id":"https://ror.org/03ywwzv91","name":"3C + Institute","types":["Company"],"links":["http://www.3cisd.com/"],"aliases":["3-C + Institute for Social Development","Communication, Cooperation, and Confidence"],"acronyms":["3-C + ISD"],"status":"active","wikipedia_url":"https://en.wikipedia.org/wiki/3C_Institute","labels":[],"country":{"country_name":"United + States","country_code":"US"},"external_ids":{"Wikidata":{"preferred":null,"all":["Q18148644"]},"GRID":{"preferred":"grid.280939.9","all":"grid.280939.9"}}}],"meta":{"types":[{"id":"company","title":"Company","count":27715},{"id":"education","title":"Education","count":19353},{"id":"nonprofit","title":"Nonprofit","count":12547},{"id":"healthcare","title":"Healthcare","count":12465},{"id":"facility","title":"Facility","count":8499},{"id":"other","title":"Other","count":7823},{"id":"government","title":"Government","count":5762},{"id":"archive","title":"Archive","count":2724}],"countries":[{"id":"us","title":"United + States of America","count":29729},{"id":"gb","title":"United Kingdom of Great + Britain and Northern Ireland","count":7166},{"id":"de","title":"Federal Republic + of Germany","count":4749},{"id":"cn","title":"People''s Republic of China","count":4501},{"id":"jp","title":"Japan","count":3701},{"id":"fr","title":"French + Republic","count":3681},{"id":"ca","title":"Canada","count":3200},{"id":"in","title":"Republic + of India","count":2821},{"id":"cz","title":"Czech Republic","count":2741},{"id":"ru","title":"Russian + Federation","count":2008}]}}' + http_version: null + recorded_at: Sun, 18 Oct 2020 15:53:10 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/graphql/types/organization_type_spec.rb b/spec/graphql/types/organization_type_spec.rb index 8ec3eec5a..36978bd49 100644 --- a/spec/graphql/types/organization_type_spec.rb +++ b/spec/graphql/types/organization_type_spec.rb @@ -534,6 +534,29 @@ end end + describe "query all organizations", vcr: true do + let(:query) do + %(query { + organizations { + totalCount + years { + id + title + count + } + } + }) + end + + it "returns organization information" do + response = LupoSchema.execute(query).as_json + + expect(response.dig("data", "organizations", "totalCount")).to eq(98332) + expect(response.dig("data", "organizations", "years").first).to eq("count"=>80248, "id"=>"2017", "title"=>"2017") + expect(response.dig("data", "organizations", "years").last).to eq("count"=>513, "id"=>"2020", "title"=>"2020") + end + end + describe "query organizations", elasticsearch: true, vcr: true do let!(:dois) { create_list(:doi, 3) } let!(:doi) { create(:doi, aasm_state: "findable", creators: