Spaces:
Sleeping
Sleeping
Initial project setup with Django, including core models, admin configuration, GraphQL schema, and data population script.
03fbd26
| import graphene | |
| from graphene_django import DjangoObjectType | |
| from graphene_django.filter import DjangoFilterConnectionField | |
| from .models import ( | |
| Institution, Author, Affiliation, Domain, Field, | |
| Subfield, Topic, AuthorTopic, Work, AuthorYearlyStats, | |
| Concept, AuthorConcept | |
| ) | |
| # === GraphQL Types === | |
| class InstitutionType(DjangoObjectType): | |
| class Meta: | |
| model = Institution | |
| fields = "__all__" | |
| filter_fields = { | |
| 'id': ['exact', 'icontains'], | |
| 'name': ['icontains', 'iexact'], | |
| 'ror_id': ['exact'], | |
| 'country_code': ['exact'], | |
| 'institution_type': ['exact'], | |
| } | |
| interfaces = (graphene.relay.Node,) | |
| class AuthorType(DjangoObjectType): | |
| class Meta: | |
| model = Author | |
| fields = "__all__" | |
| filter_fields = { | |
| 'id': ['exact', 'icontains'], | |
| 'name': ['icontains'], | |
| 'orcid': ['exact'], | |
| 'h_index': ['exact', 'gte', 'lte'], | |
| 'cited_by_count': ['gte', 'lte'], | |
| 'works_count': ['gte', 'lte'], | |
| } | |
| interfaces = (graphene.relay.Node,) | |
| class AffiliationType(DjangoObjectType): | |
| class Meta: | |
| model = Affiliation | |
| fields = "__all__" | |
| filter_fields = { | |
| 'author__id': ['exact'], | |
| 'institution__id': ['exact'], | |
| 'year': ['exact', 'gte', 'lte'], | |
| 'is_last_known': ['exact'], | |
| } | |
| interfaces = (graphene.relay.Node,) | |
| class DomainType(DjangoObjectType): | |
| class Meta: | |
| model = Domain | |
| fields = "__all__" | |
| filter_fields = ['id', 'name'] | |
| interfaces = (graphene.relay.Node,) | |
| class FieldType(DjangoObjectType): | |
| class Meta: | |
| model = Field | |
| fields = "__all__" | |
| filter_fields = { | |
| 'id': ['exact'], | |
| 'name': ['icontains'], | |
| 'domain__id': ['exact'], | |
| } | |
| interfaces = (graphene.relay.Node,) | |
| class SubfieldType(DjangoObjectType): | |
| class Meta: | |
| model = Subfield | |
| fields = "__all__" | |
| filter_fields = { | |
| 'id': ['exact'], | |
| 'name': ['icontains'], | |
| 'field__id': ['exact'], | |
| } | |
| interfaces = (graphene.relay.Node,) | |
| class TopicType(DjangoObjectType): | |
| class Meta: | |
| model = Topic | |
| fields = "__all__" | |
| filter_fields = { | |
| 'id': ['exact'], | |
| 'name': ['icontains'], | |
| 'subfield__id': ['exact'], | |
| } | |
| interfaces = (graphene.relay.Node,) | |
| class AuthorTopicType(DjangoObjectType): | |
| class Meta: | |
| model = AuthorTopic | |
| fields = "__all__" | |
| filter_fields = { | |
| 'author__id': ['exact'], | |
| 'topic__id': ['exact'], | |
| } | |
| interfaces = (graphene.relay.Node,) | |
| class WorkType(DjangoObjectType): | |
| class Meta: | |
| model = Work | |
| fields = "__all__" | |
| filter_fields = { | |
| 'id': ['exact'], | |
| 'title': ['icontains'], | |
| 'author__id': ['exact'], | |
| 'year': ['exact', 'gte', 'lte'], | |
| 'cited_by_count': ['gte', 'lte'], | |
| } | |
| interfaces = (graphene.relay.Node,) | |
| class AuthorYearlyStatsType(DjangoObjectType): | |
| class Meta: | |
| model = AuthorYearlyStats | |
| fields = "__all__" | |
| filter_fields = { | |
| 'author__id': ['exact'], | |
| 'year': ['exact'], | |
| 'works_count': ['gte', 'lte'], | |
| } | |
| interfaces = (graphene.relay.Node,) | |
| class ConceptType(DjangoObjectType): | |
| class Meta: | |
| model = Concept | |
| fields = "__all__" | |
| filter_fields = ['id', 'name', 'level', 'score'] | |
| interfaces = (graphene.relay.Node,) | |
| class AuthorConceptType(DjangoObjectType): | |
| class Meta: | |
| model = AuthorConcept | |
| fields = "__all__" | |
| filter_fields = { | |
| 'author__id': ['exact'], | |
| 'concept__id': ['exact'], | |
| } | |
| interfaces = (graphene.relay.Node,) | |
| # === Query with Filtered Connections === | |
| class Query(graphene.ObjectType): | |
| institution = graphene.relay.Node.Field(InstitutionType) | |
| all_institutions = DjangoFilterConnectionField(InstitutionType) | |
| author = graphene.relay.Node.Field(AuthorType) | |
| all_authors = DjangoFilterConnectionField(AuthorType) | |
| affiliation = graphene.relay.Node.Field(AffiliationType) | |
| all_affiliations = DjangoFilterConnectionField(AffiliationType) | |
| domain = graphene.relay.Node.Field(DomainType) | |
| all_domains = DjangoFilterConnectionField(DomainType) | |
| field = graphene.relay.Node.Field(FieldType) | |
| all_fields = DjangoFilterConnectionField(FieldType) | |
| subfield = graphene.relay.Node.Field(SubfieldType) | |
| all_subfields = DjangoFilterConnectionField(SubfieldType) | |
| topic = graphene.relay.Node.Field(TopicType) | |
| all_topics = DjangoFilterConnectionField(TopicType) | |
| author_topic = graphene.relay.Node.Field(AuthorTopicType) | |
| all_author_topics = DjangoFilterConnectionField(AuthorTopicType) | |
| work = graphene.relay.Node.Field(WorkType) | |
| all_works = DjangoFilterConnectionField(WorkType) | |
| author_yearly_stats = graphene.relay.Node.Field(AuthorYearlyStatsType) | |
| all_author_yearly_stats = DjangoFilterConnectionField( | |
| AuthorYearlyStatsType) | |
| concept = graphene.relay.Node.Field(ConceptType) | |
| all_concepts = DjangoFilterConnectionField(ConceptType) | |
| author_concept = graphene.relay.Node.Field(AuthorConceptType) | |
| all_author_concepts = DjangoFilterConnectionField(AuthorConceptType) | |
| schema = graphene.Schema(query=Query) | |