generate default graphene schema from sqlalchemy model base on graphene-sqlalchemy
just run
pip install graphene_sqlalchemy_auto
- auto add
offset
limit
totalCount
to pagination - auto add
dbId
for model's database id - mutation auto return ok for success,message for more information and output for model data
example :
from graphene_sqlalchemy_auto import QueryObjectType,MutationObjectType
from sqlalchemy.ext.declarative import declarative_base
import graphene
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
Session = sessionmaker()
class Query(QueryObjectType):
class Meta:
declarative_base = Base
exclude_models = ["User"] # exclude models
class Mutation(MutationObjectType):
class Meta:
declarative_base = Base
session=Session() # mutate used
include_object = []# you can use yourself mutation UserCreateMutation, UserUpdateMutation
schema = graphene.Schema(query=Query, mutation=Mutation)
just equal
query{
userList(filters:{name: "a"}){
edges{
node{
name
id
dbId
}
}
}
}
OR support more expr
query{
userList(filters:[{key: "name",op: "==", val: "a"}]){
edges{
node{
name
id
dbId
}
}
}
}
- ==
- !=
- >=
- <=
- >
- <
- starts
- ends
- contains
- in
- notin
- any
createUser(input:{name: "cc",password: "dd"}){
ok
output{
id
dbId
name
}
message
}
- model.class.name.lower : query a data by id
- model.class.name.decapitalize[first lower]+"List": query list
- create|update|delete+model.class.name : mutation data
about many-to-many mutation
now you can use schema everywhere.some like flask,fastapi
also more example you can find in example