Skip to main content

Framework for trivial code, Easy and Fast for learn, Easy and Fast for use

Project description

Graphene-Django-CRUDDALS

๐Ÿ‘ฉ๐Ÿฝโ€๐Ÿ’ป ๐Ÿš€ ๐Ÿ‘จ๐Ÿฝโ€๐Ÿ’ป
Framework for trivial code, easy and fast to learn and use.
Turn your Django-models into a complete GraphQL API with all CRUD operations

PyPI GitHub License Codecov Documentation Status

CRUDDALS Gif

Docs

Built with โค๏ธŽ by Juan J Cardona and contributors

๐Ÿ“‹ Table of Contents

  1. ๐Ÿš€ Getting started
  2. ๐Ÿ‘ฉโ€๐Ÿ’ป Usage
  3. ๐ŸŽ Features
  4. ๐Ÿ“š Documentation
  5. ๐Ÿ“œ License
  6. โค๏ธ Contributing
  7. ๐Ÿ“ž Contact
  8. ๐Ÿ™ Acknowledgements
  9. ๐Ÿ—บ๏ธ Roadmap

๐Ÿš€ Getting started

Prerequisites

To install this project you need to have a Django project already set up. If you don't have one, you can follow the official Django tutorial.

Installation

You can install this package using pip:

pip install graphene-django-cruddals

๐Ÿ‘ฉโ€๐Ÿ’ป Usage

To use it, simply create a new class that inherits "DjangoModelCruddals" Suppose we have the following models.

from django.db import models


class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')


class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)

Then we can create a complete CRUD+DALS for the models Question with the following code

class CruddalsQuestion(DjangoModelCruddals):
    class Meta:
        model = Question

Now you can use the schema that was generated for you,

schema = CruddalsQuestion.Schema

or use in your existing schema root Query and Mutation

class Query(
    # ... your others queries
    CruddalsQuestion.Query,
    graphene.ObjectType,
):
    pass


class Mutation(
    # ... your others mutations
    CruddalsQuestion.Mutation,
    graphene.ObjectType,
):
    pass


schema = graphene.Schema( query=Query, mutation=Mutation, )

your schema will have the following queries and mutations

Click to see the generated schema
# Queries
type Query {
  readQuestion(where: FilterQuestionInput!): QuestionType
  searchQuestions(where: FilterQuestionInput, orderBy: OrderByQuestionInput, paginated: PaginationConfigInput): QuestionPaginatedType
  listQuestions: [QuestionType!]
}

# Mutations
type Mutation {
  createQuestions(input: [CreateQuestionInput!]): CreateQuestionsPayload
  updateQuestions(input: [UpdateQuestionInput!]): UpdateQuestionsPayload
  activateQuestions(where: FilterQuestionInput!): ActivateQuestionsPayload
  deactivateQuestions(where: FilterQuestionInput!): DeactivateQuestionsPayload
  deleteQuestions(where: FilterQuestionInput!): DeleteQuestionsPayload
}


# Inputs
# - From the model: Question
input CreateQuestionInput {
  questionText: String!
  pubDate: DateTime!
}
input UpdateQuestionInput {
  id: ID!
  questionText: String
  pubDate: DateTime
}
input FilterQuestionInput {
  id: IDFilter
  questionText: StringFilter
  pubDate: DateTimeFilter
  AND: [FilterQuestionInput]
  OR: [FilterQuestionInput]
  NOT: FilterQuestionInput
}
input OrderByQuestionInput {
  id: OrderEnum
  questionText: OrderStringEnum
  pubDate: OrderEnum
}
# - Filters
input IDFilter {
  exact: ID
  iexact: ID
  gt: ID
  gte: ID
  lt: ID
  lte: ID
  in: [ID]
  contains: ID
  icontains: ID
  startswith: ID
  istartswith: ID
  endswith: ID
  iendswith: ID
  range: [ID]
  isnull: Boolean
  regex: String
  iregex: String
  containedBy: ID
}
input StringFilter {
  exact: String
  iexact: String
  gt: String
  gte: String
  lt: String
  lte: String
  in: [String]
  contains: String
  icontains: String
  startswith: String
  istartswith: String
  endswith: String
  iendswith: String
  range: [String]
  isnull: Boolean
  regex: String
  iregex: String
}
input DateTimeFilter {
  exact: DateTime
  iexact: DateTime
  gt: DateTime
  gte: DateTime
  lt: DateTime
  lte: DateTime
  in: [DateTime]
  contains: DateTime
  icontains: DateTime
  startswith: DateTime
  istartswith: DateTime
  endswith: DateTime
  iendswith: DateTime
  range: [DateTime]
  isnull: Boolean
  regex: String
  iregex: String
  year: DateTime
  month: DateTime
  day: DateTime
  weekDay: DateTime
  isoWeekDay: DateTime
  week: DateTime
  isoYear: DateTime
  quarter: DateTime
  containedBy: DateTime
  hour: DateTime
  minute: DateTime
  second: DateTime
  date: DateTime
  time: DateTime
}
# - Pagination
input PaginationConfigInput {
  page: Int = 1
  itemsPerPage: IntOrAll = "All"
}



# Types
# - From the model: Question
type QuestionType {
  id: ID
  questionText: String!
  pubDate: DateTime!
}
type QuestionPaginatedType implements PaginationInterface {
  total: Int
  page: Int
  pages: Int
  hasNext: Boolean
  hasPrev: Boolean
  indexStart: Int
  indexEnd: Int
  objects: [QuestionType!]
}
# - Payload the mutations
type CreateQuestionsPayload {
  objects: [QuestionType]
  errorsReport: [ErrorCollectionType]
}
type UpdateQuestionsPayload {
  objects: [QuestionType]
  errorsReport: [ErrorCollectionType]
}
type ActivateQuestionsPayload {
  objects: [QuestionType]
  errorsReport: [ErrorCollectionType]
}
type DeactivateQuestionsPayload {
  objects: [QuestionType]
  errorsReport: [ErrorCollectionType]
}
type DeleteQuestionsPayload {
  objects: [QuestionType]
  errorsReport: [ErrorCollectionType]
  success: Boolean
}
# - Error
type ErrorCollectionType {
  objectPosition: String
  errors: [ErrorType]
}
type ErrorType {
  field: String!
  messages: [String!]!
}



# Interfaces

interface PaginationInterface {
  total: Int
  page: Int
  pages: Int
  hasNext: Boolean
  hasPrev: Boolean
  indexStart: Int
  indexEnd: Int
}


# Scalars

"""
The `DateTime` scalar type represents a DateTime
value as specified by
[iso8601](https://en.wikipedia.org/wiki/ISO_8601).
"""
scalar DateTime
"""The page size can be int or 'All'"""
scalar IntOrAll


# Enums
enum OrderEnum {
  ASC
  DESC
}

enum OrderStringEnum {
  ASC
  DESC
  IASC
  IDESC
}

๐ŸŽ‰๐Ÿฅณ Now you can use and test in Graphiql ๐Ÿš€๐Ÿš€๐Ÿš€

๐ŸŽ Features

Status Description
โœ… Done
ใ€ฐ๏ธ In progress
โŒ Not started
Feature Status Comments
Generate ObjectType from Django model โœ… Pending for documentation
Generate InputObjectType from Django model โœ… Pending for documentation
Generate Fields from Django model โœ… Pending for documentation
Generate InputFields from Django model โœ… Pending for documentation
Generate Arguments from Django model โœ… Pending for documentation
Generate Mutations from Django model โœ… Pending for documentation
Generate Queries from Django model โœ… Pending for documentation
Generate resolvers from Django model โœ… Pending for documentation
Generate Create operation for a Django model โœ… Pending for documentation
Generate Read operation for a Django model โœ… Pending for documentation
Generate Update operation for a Django model โœ… Pending for documentation
Generate Delete operation for a Django model โœ… Pending for documentation
Generate Deactivate operation for a Django model โœ… Pending for documentation
Generate Activate operation for a Django model โœ… Pending for documentation
Generate List operation for a Django model โœ… Pending for documentation
Generate Search operation for a Django model โœ… Pending for documentation
Generate each operation, all to be performed massively โœ… Pending for documentation
Handle null and blank attribute of Django model โœ… Pending for documentation
Handle editable attribute of Django model โœ… Pending for documentation
Handle help_text attribute of Django model โœ… Pending for documentation
Handle default attribute of Django model โœ… Pending for documentation
Handle choices attribute of Django model โœ… Pending for documentation
Handle OneToOneField field of Django model โœ… Pending for documentation
Handle OneToOneRel field of Django model โœ… Pending for documentation
Handle ManyToManyField field of Django model โœ… Pending for documentation
Handle ManyToManyRel field of Django model โœ… Pending for documentation
Handle ForeignKey field of Django model โœ… Pending for documentation
Handle ManyToOneRel field of Django model โœ… Pending for documentation
Handle GenericForeignKey field of Django model โœ… Pending for documentation
Handle GenericRel field of Django model โœ… Pending for documentation
Handle FileField and ImageField fields of Django Model โœ… Pending for documentation
Handle JSONField field of Django model โœ… Pending for documentation
Allowing nested mutations at any depth level โœ… Pending for documentation
Allowing nested queries at any depth level โœ… Pending for documentation
Handle pagination of query results โœ… Pending for documentation
Handle sorting of query results โœ… Pending for documentation
Handle advanced search โœ… Pending for documentation
Handle advanced search with AND operator โœ… Pending for documentation
Handle advanced search with OR operator โœ… Pending for documentation
Handle advanced search with NOT operator โœ… Pending for documentation
Handle advanced search with relational fields operator โœ… Pending for documentation
Providing a friendly and comprehensive list of errors โœ… Pending for documentation
Allow use the ObjectTypes generated from the models โœ… Pending for documentation
Allow customizing the ObjectType generated by CRUDDALS โœ… Pending for documentation
Allow customizing the InputObjectType generated by CRUDDALS โœ… Pending for documentation
Allow customizing the Fields generated by CRUDDALS โœ… Pending for documentation
Allow customizing the InputFields generated by CRUDDALS โœ… Pending for documentation
Allow customizing the Arguments generated by CRUDDALS โœ… Pending for documentation
Allow customizing the Mutations generated by CRUDDALS โœ… Pending for documentation
Allow customizing the Queries generated by CRUDDALS โœ… Pending for documentation
Allow customizing the resolvers generated by CRUDDALS โœ… Pending for documentation
Generate all operations at the model, app, or project level โœ… Pending for documentation
Files for consuming the GraphQL API with any JavaScript client โœ… Pending for documentation
File with the queries and mutations for with GraphiQL โœ… Pending for documentation
File with the entire GraphQL schema generated โœ… Pending for documentation
Handle transactions in mutations โŒ Pending for documentation
Handle directives in queries and mutations โŒ Pending for documentation
Handle subscriptions โŒ Pending for documentation
Optimized queries and mutations โŒ Pending for documentation
Generate Types for TypeScript โŒ Pending for documentation
Generate validators for Zod, Yup, others โŒ Pending for documentation

๐Ÿ“š Documentation

You can find the full documentation here, please keep in mind that this is a work in progress.

๐Ÿ“œ License

Distributed under the MIT License. See LICENSE for more information.

โค๏ธ Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated. For more information, please read the CONTRIBUTING.md

๐Ÿ“ž Contact

๐Ÿ™ Acknowledgements

๐Ÿ—บ๏ธ Roadmap

  • Finish documentation
  • Add more examples
  • Add more features
  • Add tests
  • Add localization
  • Add SEO
  • Add analytics
  • Make social marketing
  • Add monitoring
  • Add logging
  • Add CI/CD
  • Add collaboration
  • Add communication
  • Add networking

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_cruddals-0.1.4.tar.gz (45.4 kB view details)

Uploaded Source

Built Distribution

graphene_django_cruddals-0.1.4-py3-none-any.whl (48.5 kB view details)

Uploaded Python 3

File details

Details for the file graphene_django_cruddals-0.1.4.tar.gz.

File metadata

File hashes

Hashes for graphene_django_cruddals-0.1.4.tar.gz
Algorithm Hash digest
SHA256 a2a4a5bba25af70369fc36797d6b7317a5217c8e52e7f4372cc214b88e7ae229
MD5 779cd17d6c8b874124e14654fd5f898f
BLAKE2b-256 03c9905c099241bece7ad50e17377223b9b8dab75181c15768885248b6d7a7a6

See more details on using hashes here.

File details

Details for the file graphene_django_cruddals-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for graphene_django_cruddals-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2eec3be36e1c071069260682c741adf9eb456f35382daf21a351805f016a2ee9
MD5 e59a2255901c2937bc47eda40188b580
BLAKE2b-256 7fbfe23a4998dd09e45bb1dcfd2c622b871925c84d0a5ec0c346eae9ec29453f

See more details on using hashes here.

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