graphql-python / graphql-python/graphene

Graphene acts as Data Cache layer like open query engine.

Ouverte
#1,319 0 commentaires 4 réactions 0 personnes assignées Voir sur GitHub
✨ enhancement
Langage dominant
Python
Étoiles
8.2k
Forks
818
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

Hi Team,

My name is Giang, I would like to propose a new feature for caching results on certain selected nodes with class Meta: cache = True.
I would to do data analytics on big data lake s3 using pyspark mapping spark (or other libraries) schema to graphene schema and I would like to utilize server side graphql as **cache layer** . In other words, I would like to treat graphql as a next custom ORM for pyspark or other dataframe libraries.

When query data, I would like to get custom field results on that node and cache it for 30 minutes **(Where big data speed of access to data lake s3 does not matter, but rather than the aggregations of results)**

@jkimbo cc
![network graph](https://user-images.githubusercontent.com/37028078/113496031-b4004580-9549-11eb-850e-ba64643ec234.png)
Cached data will need to be run when there is no cached data when query and updating when using mutation on the Node

![network graph 2](https://user-images.githubusercontent.com/37028078/113496040-bbbfea00-9549-11eb-8ec0-124a5976042a.png)
And we also have a scheme for updating from childs to parents

```
import graphene
Import os
os.env[“GRAPHENE_CACHE_TIME”] = 1800

class Company(graphene.ObjectType):
class Meta:
interfaces = (relay.Node,)
cache = True
name = graphene.String()
revenue = graphene.Float()
datetime = graphene.DateTime()
if there are nested child (update all parent nodes cache)

@classmethod // cache this result on query
get_all_companies(cls, info):
return [cls(**data) for data in database.values()]
@classmethod // cache this result by different pairs of inputs on query
get_company_report_by_period(cls, info, name, period):
selected_data = [data for data in database.values() if name == data[“name”] and period in data[“datetime”]]
return {
“name”: name,
“revenue”: sum(data[“revenue”] for data in selected_data),
“datetime”: period
}

class Query(graphene.ObjectType):
get_report = graphene.List(Company)
get_company_report_period = graphene.Field(Company)

def resolve_get_report(_, info):
return Company.get_all_companies()
def resolve_get_company_report_period(_, info, name, period):
return Company.get_company_report_by_period(name, period)

database = {
“0”: {
“name”: “amazon”,
“revenue”: 1000,
“datetime”: “2021-04-01”
},
“1”: {
“name”: “amazon”,
“revenue”: 1000,
“datetime”: “2021-05-01”
},
“2”: {
“name”: “google”,
“revenue”: 1000,
“datetime”: “2021-06-01”
}
}
```
Kind regards
Giang

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

L’issue n’identifie au départ aucun fichier du dépôt, test ou point d’entrée. Il faut d’abord clarifier la portée du cache, la génération des clés, l’expiration, l’invalidation lors des mutations et le comportement de mise à jour entre les parents et les enfants ; la finalisation nécessiterait une conception approuvée ainsi que l’implémentation et les tests correspondants.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
graphql, python
Domaine
backend-api-design
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
20/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.