All Projects → graphql-python → Graphene Sqlalchemy

graphql-python / Graphene Sqlalchemy

Licence: mit
Graphene SQLAlchemy integration

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Graphene Sqlalchemy

Flask Graphene Sqlalchemy
A demo project for Flask + GraphQL (With Graphene & SQLAlchemy)
Stars: ✭ 117 (-85.1%)
Mutual labels:  graphql, sqlalchemy
Flask Graphene Sqlalchemy
⚗️Project template to build a GraphQL API in Python
Stars: ✭ 109 (-86.11%)
Mutual labels:  graphql, sqlalchemy
Graphql Prisma Typescript
🏡 GraphQL server reference implementation (Airbnb clone) in Typescript using Prisma & graphql-yoga
Stars: ✭ 723 (-7.9%)
Mutual labels:  graphql
Graphql Yoga
🧘 Fully-featured GraphQL Server with focus on easy setup, performance & great developer experience
Stars: ✭ 6,573 (+737.32%)
Mutual labels:  graphql
Eventsourcing
A library for event sourcing in Python.
Stars: ✭ 760 (-3.18%)
Mutual labels:  sqlalchemy
Go Gin Api
基于 Gin 进行模块化设计的 API 框架,封装了常用功能,使用简单,致力于进行快速的业务研发。比如,支持 cors 跨域、jwt 签名验证、zap 日志收集、panic 异常捕获、trace 链路追踪、prometheus 监控指标、swagger 文档生成、viper 配置文件解析、gorm 数据库组件、gormgen 代码生成工具、graphql 查询语言、errno 统一定义错误码、gRPC 的使用 等等。
Stars: ✭ 730 (-7.01%)
Mutual labels:  graphql
Elide
Elide is a Java library that lets you stand up a GraphQL/JSON-API web service with minimal effort.
Stars: ✭ 766 (-2.42%)
Mutual labels:  graphql
Adrenaline
Simple Relay alternative
Stars: ✭ 720 (-8.28%)
Mutual labels:  graphql
Chimp
Tooling that helps you do quality, faster.
Stars: ✭ 783 (-0.25%)
Mutual labels:  graphql
Node Graphql Server
Boilerplate code for scalable, production-ready GraphQL servers
Stars: ✭ 761 (-3.06%)
Mutual labels:  graphql
Storefront Api Examples
Example custom storefront applications built on Shopify's Storefront API
Stars: ✭ 769 (-2.04%)
Mutual labels:  graphql
Quicktype
Generate types and converters from JSON, Schema, and GraphQL
Stars: ✭ 7,459 (+850.19%)
Mutual labels:  graphql
Type Graphql
Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
Stars: ✭ 6,864 (+774.39%)
Mutual labels:  graphql
Just Api
💥 Test REST, GraphQL APIs
Stars: ✭ 768 (-2.17%)
Mutual labels:  graphql
Nexus Plugin Prisma
A plugin for Nexus that integrates Prisma
Stars: ✭ 728 (-7.26%)
Mutual labels:  graphql
Hasura Backend Plus
🔑Auth and 📦Storage for Hasura. The quickest way to get Auth and Storage working for your next app based on Hasura.
Stars: ✭ 776 (-1.15%)
Mutual labels:  graphql
Accent
The first developer-oriented translation tool. True asynchronous flow between translators and your team.
Stars: ✭ 721 (-8.15%)
Mutual labels:  graphql
Tyk
Tyk Open Source API Gateway written in Go, supporting REST, GraphQL, TCP and gRPC protocols
Stars: ✭ 6,968 (+787.64%)
Mutual labels:  graphql
Githubv4
Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql).
Stars: ✭ 760 (-3.18%)
Mutual labels:  graphql
Graphiti
Stylish Graph APIs
Stars: ✭ 783 (-0.25%)
Mutual labels:  graphql

Please read UPGRADE-v2.0.md to learn how to upgrade to Graphene 2.0.


Graphene Logo Graphene-SQLAlchemy Build Status PyPI version Coverage Status

A SQLAlchemy integration for Graphene.

Installation

For instaling graphene, just run this command in your shell

pip install "graphene-sqlalchemy>=2.0"

Examples

Here is a simple SQLAlchemy model:

from sqlalchemy import Column, Integer, String

from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class UserModel(Base):
    __tablename__ = 'user'
    id = Column(Integer, primary_key=True)
    name = Column(String)
    last_name = Column(String)

To create a GraphQL schema for it you simply have to write the following:

import graphene
from graphene_sqlalchemy import SQLAlchemyObjectType

class User(SQLAlchemyObjectType):
    class Meta:
        model = UserModel
        # use `only_fields` to only expose specific fields ie "name"
        # only_fields = ("name",)
        # use `exclude_fields` to exclude specific fields ie "last_name"
        # exclude_fields = ("last_name",)

class Query(graphene.ObjectType):
    users = graphene.List(User)

    def resolve_users(self, info):
        query = User.get_query(info)  # SQLAlchemy query
        return query.all()

schema = graphene.Schema(query=Query)

Then you can simply query the schema:

query = '''
    query {
      users {
        name,
        lastName
      }
    }
'''
result = schema.execute(query, context_value={'session': db_session})

You may also subclass SQLAlchemyObjectType by providing abstract = True in your subclasses Meta:

from graphene_sqlalchemy import SQLAlchemyObjectType

class ActiveSQLAlchemyObjectType(SQLAlchemyObjectType):
    class Meta:
        abstract = True

    @classmethod
    def get_node(cls, info, id):
        return cls.get_query(info).filter(
            and_(cls._meta.model.deleted_at==None,
                 cls._meta.model.id==id)
            ).first()

class User(ActiveSQLAlchemyObjectType):
    class Meta:
        model = UserModel

class Query(graphene.ObjectType):
    users = graphene.List(User)

    def resolve_users(self, info):
        query = User.get_query(info)  # SQLAlchemy query
        return query.all()

schema = graphene.Schema(query=Query)

Full Examples

To learn more check out the following examples:

Contributing

See CONTRIBUTING.md

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].