Django Project Cruddals¶
A base class for defining GraphQL schemas for a Django project using Cruddals.
This class provides methods to dynamically create GraphQL schemas for each app in the project based on provided settings.
This class is a wrapper around DjangoAppCruddals
to generate GraphQL schema for each app in the project, avoiding the need to define a subclass for each app.
Otherwise this approach yet allow customizing the behavior of the generated GraphQL schema for each app with the same attributes as DjangoAppCruddals
but in a dictionary format.
Attributes:
Name | Type | Description |
---|---|---|
apps |
Union[Literal['__all__'], Tuple[str, ...]]
|
Names of Django apps for which schemas will be generated. Defaults to "all", meaning all apps in the project. |
schema |
Schema
|
The generated GraphQL schema for the project. |
Query |
TypeAlias
|
The combined Query object for the project. |
Mutation |
TypeAlias
|
The combined Mutation object for the project. |
meta |
A dictionary with the name of the apps as keys and the generated classes as values. |
To use this class, define a subclass and include a Meta
class with the required attributes.
Example Usage:¶
from graphene_django_cruddals import DjangoProjectCruddals
class YourProjectCruddals(DjangoProjectCruddals):
class Meta:
apps = "__all__"
from graphene_django_cruddals import DjangoProjectCruddals
class YourProjectCruddals(DjangoProjectCruddals):
class Meta:
apps = ("your_app1", "your_app2")
# exclude_apps = ("your_app1",)
cruddals_interfaces = (CustomCruddalsInterface,)
# exclude_cruddals_interfaces = ("CustomCruddalsInterface",)
settings_for_app = {
"your_app1": {
"models": ("YourModel1", "YourModel2"),
# "exclude_models": ("YourModel1",),
"prefix": "New",
"suffix": "Suffix",
"cruddals_interfaces": (CustomCruddalsInterfaceForYourApp1,),
# "exclude_cruddals_interfaces": ("CustomCruddalsInterface",),
"functions": ("create", "read", "update", "delete", "deactivate", "activate", "list", "search"),
# "exclude_functions": ("create",),
"settings_for_model": {
"YourModel1": {
"functions": ("create", "read", "update", "delete", "deactivate", "activate", "list", "search"),
# "exclude_functions": ("create",),
"prefix": "New",
"suffix": "Suffix",
"cruddals_interfaces": (CustomCruddalsInterfaceForYourModel1,),
# "exclude_cruddals_interfaces": ("CustomCruddalsInterface",),
"field_for_activate_deactivate": "is_enabled",
},
"YourModel2": {
# ...
},
},
},
"your_app2": {
# ...
},
}
Meta Class Options:¶
Note
These options can also be seen below in the definition of __init_subclass_with_meta__
method.
*apps (Union[Literal["__all__"], Tuple[str, ...]]):* Names of Django apps for which schemas will be generated. Defaults to "__all__", meaning all apps in the project.
*exclude_apps (Tuple[str, ...]):* Names of apps to exclude from schema generation. Defaults to ().
*cruddals_interfaces (Tuple[Type[Any], ...], optional):* A tuple of additional Cruddals interfaces to be implemented by the generated GraphQL Schema. Defaults to ().
*settings_for_app (Dict[str, Any], optional):* A dictionary with the name of the apps as keys and a dictionary with the settings for each app as values for overriding the default settings of the generated GraphQL Schema. Defaults to {}.
*functions (Tuple[FunctionType, ...], optional):* Functions to include in the schemas can be "create", "read", "update", "delete", "deactivate", "activate", "list", "search" .
*exclude_functions (Tuple[FunctionType, ...], optional):* Functions to exclude from schema generation. Defaults to ().
Source code in graphene_django_cruddals/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 |
|
__init_subclass_with_meta__
classmethod
¶
__init_subclass_with_meta__(
apps="__all__",
exclude_apps=(),
cruddals_interfaces=(),
settings_for_app=None,
functions=(),
exclude_functions=(),
**kwargs
)
Initialize the subclass with meta settings and dynamically create GraphQL schemas for apps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
apps |
str or tuple
|
Names of Django apps for which schemas will be generated. Defaults to "all", meaning all apps in the project. |
'__all__'
|
exclude_apps |
tuple
|
Names of apps to exclude from schema generation. |
()
|
cruddals_interfaces |
tuple
|
Additional GraphQL cruddals_interfaces to include in the schemas. |
()
|
settings_for_app |
dict
|
Settings specific to each app for schema generation. |
None
|
functions |
tuple
|
Functions to include in the schemas can be "create", "read", "update", "delete", "deactivate", "activate", "list", "search" . |
()
|
exclude_functions |
tuple
|
Functions to exclude from schema generation. |
()
|
**kwargs |
Any
|
Additional keyword arguments. |
{}
|
Source code in graphene_django_cruddals/main.py
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
|