GithubHelp home page GithubHelp logo

rcdevgames / graphene-sqlalchemy-auto Goto Github PK

View Code? Open in Web Editor NEW

This project forked from goodking-bq/graphene-sqlalchemy-auto

0.0 1.0 0.0 99 KB

graphene-sqlalchemy-auto

License: MIT License

Python 100.00%

graphene-sqlalchemy-auto's Introduction

publish

generate default graphene schema from sqlalchemy model base on graphene-sqlalchemy

Installation

just run

pip install graphene_sqlalchemy_auto

Features

  • 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

How To Use

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)

Query example

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
      }
    }
  }
}

op supports:

  • ==
  • !=
  • >=
  • <=
  • >
  • <
  • starts
  • ends
  • contains
  • in
  • notin
  • any

Mutation example

 createUser(input:{name: "cc",password: "dd"}){
    ok
    output{
      id
      dbId
      name
    }
    message
  }

about Schema names

  • 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

graphene-sqlalchemy-auto's People

Contributors

goodking-bq avatar hjewkes avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.