diff --git a/.gitignore b/.gitignore index 46a8972..668fa65 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,8 @@ /rails/node_modules +/node_modules + # -- React -- /react/dist diff --git a/docker-compose.yml b/docker-compose.yml index 0484af9..da25991 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,11 +10,15 @@ services: POSTGRES_DB: bookworm_production POSTGRES_PASSWORD: $POSTGRES_PASSWORD healthcheck: - test: [ "CMD-SHELL", "pg_isready -d bookworm_production -U postgres" ] + test: [ "CMD-SHELL", "pg_isready -d bookworm_production -U bookworm" ] interval: 10s timeout: 5s retries: 10 + networks: + - bookworm + hostname: db rails: + hostname: rails build: ./rails container_name: bookworm-rails command: "bundle exec rails s -p 3001 -b '0.0.0.0'" @@ -34,6 +38,9 @@ services: depends_on: db: condition: service_healthy + networks: + - bookworm + react: build: ./react container_name: bookworm-react @@ -41,13 +48,14 @@ services: environment: NODE_ENV: production RAILS_API_URL: $RAILS_API_URL - ports: - - 3000:80 healthcheck: test: [ "CMD-SHELL", "wget --no-verbose --spider --tries=1 localhost:3000 || exit 1" ] interval: 10s timeout: 5s retries: 10 + hostname: bookworm-react + networks: + - bookworm depends_on: db: condition: service_healthy @@ -68,9 +76,10 @@ services: condition: service_healthy react: condition: service_healthy + networks: + - bookworm volumes: postgres_data: {} networks: - default: - name: bookworm + bookworm: diff --git a/nginx/conf.d/bookworm-ssl.conf b/nginx/conf.d/bookworm-ssl.conf index e6680af..2f98d89 100644 --- a/nginx/conf.d/bookworm-ssl.conf +++ b/nginx/conf.d/bookworm-ssl.conf @@ -1,12 +1,12 @@ server { - listen 443; + listen 443 ssl; server_name bookworm; ssl_certificate /etc/ssl/certificate.pem; ssl_certificate_key /etc/ssl/key.pem; location /graphql { - proxy_pass http://bookworm-rails:3001/graphql; + proxy_pass http://rails:3001/graphql; proxy_redirect default; proxy_http_version 1.1; diff --git a/nginx/conf.d/bookworm.conf b/nginx/conf.d/bookworm.conf index 2205303..1e1d059 100644 --- a/nginx/conf.d/bookworm.conf +++ b/nginx/conf.d/bookworm.conf @@ -3,7 +3,7 @@ server { server_name bookworm; location /graphql { - proxy_pass http://bookworm-rails:3001/graphql; + proxy_pass http://rails:3001/graphql; proxy_redirect default; proxy_http_version 1.1; diff --git a/rails/app/graphql/book_worm_schema.rb b/rails/app/graphql/book_worm_schema.rb index 3d461c0..6f78b85 100644 --- a/rails/app/graphql/book_worm_schema.rb +++ b/rails/app/graphql/book_worm_schema.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class BookWormSchema < GraphQL::Schema - mutation(Types::MutationType) + # mutation(Types::MutationType) query(Types::QueryType) # For batch-loading (see https://graphql-ruby.org/dataloader/overview.html) diff --git a/rails/app/graphql/types/author_type.rb b/rails/app/graphql/types/author_type.rb index 9b8ae07..6d88e57 100644 --- a/rails/app/graphql/types/author_type.rb +++ b/rails/app/graphql/types/author_type.rb @@ -17,19 +17,34 @@ def works object.works end - field :authors_ids, Types::AuthorsIdsType - def authors_ids - object.authors_ids + field :datasets, [Types::WorkType] + def datasets + object.works.where(work_type: "dataset") + end + + field :articles, [Types::WorkType] + def articles + object.works.where(work_type: "article") + end + + field :scopus, String + def scopus + object.authors_ids.scopus + end + + field :wikipedia, String + def wikipedia + object.authors_ids.wikipedia + end + + field :mag, String + def mag + object.authors_ids.mag end field :institutions, [Types::InstitutionType] def institutions object.institutions.uniq # move this to the Author model probably end - - field :authors_counts_by_year, [Types::AuthorsCountsByYearType] - def authors_counts_by_year - object.authors_counts_by_year - end end end diff --git a/rails/app/graphql/types/authors_counts_by_year_type.rb b/rails/app/graphql/types/authors_counts_by_year_type.rb deleted file mode 100644 index a81de89..0000000 --- a/rails/app/graphql/types/authors_counts_by_year_type.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -module Types - class AuthorsCountsByYearType < Types::BaseObject - field :id, ID, null: false - field :author_openalex_id, String - field :year, Integer - field :works_count, Integer - field :cited_by_count, Integer - field :oa_works_count, Integer - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/authors_ids_type.rb b/rails/app/graphql/types/authors_ids_type.rb deleted file mode 100644 index 3acef48..0000000 --- a/rails/app/graphql/types/authors_ids_type.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -module Types - class AuthorsIdsType < Types::BaseObject - field :id, ID, null: false - field :author_openalex_id, String - field :orcid, String - field :scopus, String - field :twitter, String - field :wikipedia, String - field :mag, String - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/institution_type.rb b/rails/app/graphql/types/institution_type.rb index 33fe4f9..c79d6db 100644 --- a/rails/app/graphql/types/institution_type.rb +++ b/rails/app/graphql/types/institution_type.rb @@ -20,9 +20,53 @@ class InstitutionType < Types::BaseObject field :updated_at, GraphQL::Types::ISO8601DateTime, null: false field :authors, [Types::AuthorType] - def authors - object.authors + object.authors.uniq + end + + field :wikidata, String + def wikidata + object.institutions_ids.wikidata + end + + field :wikipedia, String + def wikipedia + object.institutions_ids.wikipedia + end + + field :mag, String + def mag + object.institutions_ids.mag + end + + field :grid, String + def grid + object.institutions_ids.grid + end + + field :city, String + def city + object.institutions_geo.city + end + + field :region, String + def region + object.institutions_geo.region + end + + field :country, String + def country + object.institutions_geo.country + end + + field :latitude, Float + def latitude + object.institutions_geo.latitude + end + + field :longitude, Float + def longitude + object.institutions_geo.longitude end end end diff --git a/rails/app/graphql/types/institutions_counts_by_year_type.rb b/rails/app/graphql/types/institutions_counts_by_year_type.rb deleted file mode 100644 index d321539..0000000 --- a/rails/app/graphql/types/institutions_counts_by_year_type.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -module Types - class InstitutionsCountsByYearType < Types::BaseObject - field :id, ID, null: false - field :institution_openalex_id, String - field :year, Integer - field :works_count, Integer - field :cited_by_count, Integer - field :oa_works_count, Integer - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/institutions_geo_type.rb b/rails/app/graphql/types/institutions_geo_type.rb deleted file mode 100644 index 55e1c1f..0000000 --- a/rails/app/graphql/types/institutions_geo_type.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module Types - class InstitutionsGeoType < Types::BaseObject - field :id, ID, null: false - field :institution_openalex_id, String - field :city, String - field :geonames_city_id, Integer - field :region, String - field :country_code, String - field :country, String - field :latitude, Float - field :longitude, Float - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/institutions_ids_type.rb b/rails/app/graphql/types/institutions_ids_type.rb deleted file mode 100644 index 6028b06..0000000 --- a/rails/app/graphql/types/institutions_ids_type.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -module Types - class InstitutionsIdsType < Types::BaseObject - field :id, ID, null: false - field :institution_openalex_id, String - field :ror, String - field :grid, String - field :wikipedia, String - field :wikidata, String - field :mag, String - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/mutation_type.rb b/rails/app/graphql/types/mutation_type.rb index 523b451..f8c7f71 100644 --- a/rails/app/graphql/types/mutation_type.rb +++ b/rails/app/graphql/types/mutation_type.rb @@ -2,7 +2,7 @@ module Types class MutationType < Types::BaseObject - field :register_user, mutation: Mutations::RegisterUser + # field :register_user, mutation: Mutations::RegisterUser # field :sign_in, mutation: Mutations::SignIn # # field :sign_out, mutation: Mutations::SignOut diff --git a/rails/app/graphql/types/publisher_type.rb b/rails/app/graphql/types/publisher_type.rb index 36219f7..f1354c4 100644 --- a/rails/app/graphql/types/publisher_type.rb +++ b/rails/app/graphql/types/publisher_type.rb @@ -14,5 +14,15 @@ class PublisherType < Types::BaseObject field :sources_api_url, String field :created_at, GraphQL::Types::ISO8601DateTime, null: false field :updated_at, GraphQL::Types::ISO8601DateTime, null: false + + field :ror, String + def ror + object.publishers_ids.ror + end + + field :wikidata, String + def wikidata + object.publishers_ids.wikidata + end end end diff --git a/rails/app/graphql/types/publishers_counts_by_year_type.rb b/rails/app/graphql/types/publishers_counts_by_year_type.rb deleted file mode 100644 index ece0584..0000000 --- a/rails/app/graphql/types/publishers_counts_by_year_type.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -module Types - class PublishersCountsByYearType < Types::BaseObject - field :id, ID, null: false - field :publisher_openalex_id, String - field :year, Integer - field :works_count, Integer - field :cited_by_count, Integer - field :oa_works_count, Integer - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/publishers_ids_type.rb b/rails/app/graphql/types/publishers_ids_type.rb deleted file mode 100644 index 1f075c5..0000000 --- a/rails/app/graphql/types/publishers_ids_type.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -module Types - class PublishersIdsType < Types::BaseObject - field :id, ID, null: false - field :publisher_openalex_id, String - field :ror, String - field :wikidata, String - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/query_type.rb b/rails/app/graphql/types/query_type.rb index f19f70d..8a1c9c0 100644 --- a/rails/app/graphql/types/query_type.rb +++ b/rails/app/graphql/types/query_type.rb @@ -40,11 +40,21 @@ def nodes(ids:) null: true, description: 'Fetches an institution by ROR' do argument :ror, String, required: true - end + end def institution_by_ror(ror:) Institution.find_by(ror: ror) end + field :institution_by_name, + Types::InstitutionType, + null: true, + description: 'Fetches an institution by name' do + argument :name, String, required: true + end + def institution_by_name(name:) + Institution.find_by(display_name: name) + end + # author entry points field :author_by_openalex_id, diff --git a/rails/app/graphql/types/source_type.rb b/rails/app/graphql/types/source_type.rb index b9f2888..a3f97a6 100644 --- a/rails/app/graphql/types/source_type.rb +++ b/rails/app/graphql/types/source_type.rb @@ -16,5 +16,30 @@ class SourceType < Types::BaseObject field :works_api_url, String field :created_at, GraphQL::Types::ISO8601DateTime, null: false field :updated_at, GraphQL::Types::ISO8601DateTime, null: false + + field :issn_l, String + def issn_l + object.source_ids.issn_l + end + + field :issn, String + def issn + object.sources_ids.issn + end + + field :mag, String + def mag + object.sources_ids.mag + end + + field :wikidata, String + def wikidata + object.sources_ids.wikidata + end + + field :fatcat, String + def fatcat + object.sources_ids.fatcat + end end end diff --git a/rails/app/graphql/types/sources_counts_by_year_type.rb b/rails/app/graphql/types/sources_counts_by_year_type.rb deleted file mode 100644 index 53efd0a..0000000 --- a/rails/app/graphql/types/sources_counts_by_year_type.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -module Types - class SourcesCountsByYearType < Types::BaseObject - field :id, ID, null: false - field :source_openalex_id, String - field :year, Integer - field :works_count, Integer - field :cited_by_count, Integer - field :oa_works_count, Integer - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/sources_ids_type.rb b/rails/app/graphql/types/sources_ids_type.rb deleted file mode 100644 index 6b1f4af..0000000 --- a/rails/app/graphql/types/sources_ids_type.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -module Types - class SourcesIdsType < Types::BaseObject - field :id, ID, null: false - field :source_openalex_id, String - field :issn_l, GraphQL::Types::JSON - field :issn, String - field :mag, String - field :wikidata, String - field :fatcat, String - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/work_type.rb b/rails/app/graphql/types/work_type.rb index e4260fd..e7ab5f7 100644 --- a/rails/app/graphql/types/work_type.rb +++ b/rails/app/graphql/types/work_type.rb @@ -34,19 +34,19 @@ def referenced_works object.referenced_works end + field :referenced_articles, [Types::WorkType] + def referenced_articles + object.referenced_works.where(work_type: "article") + end + field :referencing_works, [Types::WorkType] def referencing_works object.referencing_works end - field :works_open_access, Types::WorksOpenAccessType - def works_open_access - object.works_open_access - end - - field :works_biblio, Types::WorksBiblioType - def works_biblio - object.works_biblio + field :referencing_articles, [Types::WorkType] + def referencing_articles + object.referencing_articles.where(work_type: "article") end field :topics, [Types::TopicType] @@ -54,9 +54,74 @@ def topics object.topics end - field :works_ids, Types::WorksIdsType - def works_ids - object.works_ids + field :is_oa, Boolean + def is_oa + object.works_open_access.is_oa + end + + field :oa_status, String + def oa_status + object.works_open_access.oa_status + end + + field :oa_url, String + def oa_url + object.works_open_access.oa_url + end + + field :volume, String + def volume + object.works_biblio.volume + end + + field :issue, String + def issue + object.works_biblio.issue + end + + field :first_page, String + def first_page + object.works_biblio.first_page + end + + field :last_page, String + def last_page + object.works_biblio.last_page + end + + field :pmid, String + def pmid + object.works_ids.pmid + end + + field :pmcid, String + def pmcid + object.works_ids.pmcid + end + + field :landing_page_url, String + def landing_page_url + object.works_best_oa_location.landing_page_url + end + + field :pdf_url, String + def pdf_url + object.works_best_oa_location.pdf_url + end + + field :license, String + def license + object.works_best_oa_location.license + end + + field :version, String + def version + object.works_best_oa_location.version + end + + field :any_repository_has_fulltext, Boolean + def any_repository_has_fulltext + object.works_open_access.any_repository_has_fulltext end end end diff --git a/rails/app/graphql/types/works_best_oa_location_type.rb b/rails/app/graphql/types/works_best_oa_location_type.rb deleted file mode 100644 index 2c06f86..0000000 --- a/rails/app/graphql/types/works_best_oa_location_type.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -module Types - class WorksBestOaLocationType < Types::BaseObject - field :id, ID, null: false - field :work_openalex_id, String - field :source_openalex_id, String - field :landing_page_url, String - field :pdf_url, String - field :is_oa, Boolean - field :version, String - field :license, String - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/works_biblio_type.rb b/rails/app/graphql/types/works_biblio_type.rb deleted file mode 100644 index 94e26fe..0000000 --- a/rails/app/graphql/types/works_biblio_type.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -module Types - class WorksBiblioType < Types::BaseObject - field :id, ID, null: false - field :work_openalex_id, String - field :volume, String - field :issue, String - field :first_page, String - field :last_page, String - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/works_ids_type.rb b/rails/app/graphql/types/works_ids_type.rb deleted file mode 100644 index 23b327f..0000000 --- a/rails/app/graphql/types/works_ids_type.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -module Types - class WorksIdsType < Types::BaseObject - field :id, ID, null: false - field :work_openalex_id, String - field :doi, String - field :mag, String - field :pmid, String - field :pmcid, String - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/works_location_type.rb b/rails/app/graphql/types/works_location_type.rb deleted file mode 100644 index 6ae3234..0000000 --- a/rails/app/graphql/types/works_location_type.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -module Types - class WorksLocationType < Types::BaseObject - field :id, ID, null: false - field :work_openalex_id, String - field :source_openalex_id, String - field :landing_page_url, String - field :pdf_url, String - field :is_oa, Boolean - field :version, String - field :license, String - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/works_open_access_type.rb b/rails/app/graphql/types/works_open_access_type.rb deleted file mode 100644 index 22ec290..0000000 --- a/rails/app/graphql/types/works_open_access_type.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -module Types - class WorksOpenAccessType < Types::BaseObject - field :id, ID, null: false - field :work_openalex_id, String - field :is_oa, Boolean - field :oa_status, String - field :oa_url, String - field :any_repository_has_fulltext, Boolean - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/graphql/types/works_primary_location_type.rb b/rails/app/graphql/types/works_primary_location_type.rb deleted file mode 100644 index 213b3cc..0000000 --- a/rails/app/graphql/types/works_primary_location_type.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -module Types - class WorksPrimaryLocationType < Types::BaseObject - field :id, ID, null: false - field :work_openalex_id, String - field :source_openalex_id, String - field :landing_page_url, String - field :pdf_url, String - field :is_oa, Boolean - field :version, String - field :license, String - field :created_at, GraphQL::Types::ISO8601DateTime, null: false - field :updated_at, GraphQL::Types::ISO8601DateTime, null: false - end -end diff --git a/rails/app/models/institution.rb b/rails/app/models/institution.rb index 20bf1f5..b472c3e 100644 --- a/rails/app/models/institution.rb +++ b/rails/app/models/institution.rb @@ -1,9 +1,17 @@ # frozen_string_literal: true class Institution < ApplicationRecord - has_many :institutions_counts_by_year - has_one :institutions_geo - has_one :institutions_ids + has_many :institutions_counts_by_year, + primary_key: :institution_openalex_id, + foreign_key: :institution_openalex_id + + has_one :institutions_geo, + primary_key: :institution_openalex_id, + foreign_key: :institution_openalex_id + + has_one :institutions_ids, + primary_key: :institution_openalex_id, + foreign_key: :institution_openalex_id has_many :institutions_associated_institutions, foreign_key: :associated_institution_openalex_id, diff --git a/rails/config/database.yml b/rails/config/database.yml index 886144f..0f80602 100644 --- a/rails/config/database.yml +++ b/rails/config/database.yml @@ -2,7 +2,7 @@ default: &default adapter: postgresql encoding: unicode username: bookworm - # password: <%= ENV["POSTGRES_PASSWORD"] %> + password: <%= ENV["POSTGRES_PASSWORD"] %> pool: 5 development: diff --git a/react/index.html b/react/index.html index cd83418..bb47cfb 100644 --- a/react/index.html +++ b/react/index.html @@ -1,13 +1,16 @@ -
- - - -