Skip to main content

deploy orm django to a graphql API easily

Project description

Graphene-Django-Crud

Inspired by prisma-nexus and graphene-django-extras, This package turns the django orm into a graphql API

Installation

For installing graphene-django-crud, just run this command in your shell:

pip install graphene-django-crud

Documentation:

Simple usage

from django.contrib.auth.models import User, Group
from graphene_django_crud.types import DjangoGrapheneCRUD
import graphene

class UserType(DjangoGrapheneCRUD):
    class Meta:
        model = User

class Query(graphene.ObjectType):
    user = UserType.ReadField()
    users = UserType.BatchReadField()

class Mutation(graphene.ObjectType):
    user_create = UserType.CreateField()
    user_update = UserType.UpdatedField()
    user_delete = UserType.DeleteField()

class Subscription(graphene.ObjectType):
    pass

schema = graphene.Schema(
    query=Query, 
    mutation=Mutation, 
    #subscription=Subscription
    )
show the generated graphql schema ``` schema { query: Query mutation: Mutation }
scalar DateTime

input DatetimeFilter {
equals: DateTime
in: [DateTime]
gt: DateTime
gte: DateTime
lt: DateTime
lte: DateTime
}

type ErrorType {
field: String!
messages: [String!]!
}

input IntFilter {
equals: Int
in: [Int]
gt: Int
gte: Int
lt: Int
lte: Int
contains: Int
startswith: Int
endswith: Int
regex: String
}

type Mutation {
userCreate(input: UserCreateInput!): UserMutationType
userUpdate(input: UserUpdateInput!, where: UserWhereUniqueInput!): UserMutationType
userDelete(where: UserWhereUniqueInput!): UserMutationType
}

type Query {
user(where: UserWhereUniqueInput): UserType
users(where: UserWhereWithOperatorInput, limit: Int, offset: Int, orderBy: [String]): UserNodeType
}

input StringFilter {
equals: String
in: [String]
contains: String
startswith: String
endswith: String
regex: String
}

input UserCreateInput {
password: String!
lastLogin: DateTime
isSuperuser: Boolean
username: String!
firstName: String
lastName: String
email: String
isStaff: Boolean
isActive: Boolean
dateJoined: DateTime
}

type UserMutationType {
ok: Boolean
errors: [ErrorType]
result: UserType
}

type UserNodeType {
count: Int
data: [UserType]
}

type UserType {
id: ID!
password: String
lastLogin: DateTime
isSuperuser: Boolean
username: String
firstName: String
lastName: String
email: String
isStaff: Boolean
isActive: Boolean
dateJoined: DateTime
}

input UserUpdateInput {
password: String
lastLogin: DateTime
isSuperuser: Boolean
username: String
firstName: String
lastName: String
email: String
isStaff: Boolean
isActive: Boolean
dateJoined: DateTime
}

input UserWhereUniqueInput {
id: ID
username: String
}

input UserWhereWithOperatorInput {
id: IntFilter
password: StringFilter
lastLogin: DatetimeFilter
isSuperuser: Boolean
username: StringFilter
firstName: StringFilter
lastName: StringFilter
email: StringFilter
isStaff: Boolean
isActive: Boolean
dateJoined: DatetimeFilter
OR: [UserWhereWithOperatorInput]
AND: [UserWhereWithOperatorInput]
NOT: UserWhereWithOperatorInput
}
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphene-django-crud-1.0.1.tar.gz (14.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page