Spaces:
Sleeping
Sleeping
File size: 5,556 Bytes
03fbd26 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
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)
|