Skip to content

Commit

Permalink
Merge pull request #12 from yefeza/develop
Browse files Browse the repository at this point in the history
Version 1.2.9
  • Loading branch information
yefeza authored Oct 19, 2023
2 parents bdb08ab + c58f6ed commit 9332455
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 63 deletions.
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ When the SessionManager is used, the operations related to authentication are:
- social_login (Mutation)
- actual_user (Query)

This package don't limit to use this basic operations. Custom operations can be defined on classic style of Graphene and Graphene-Django and finally can be merged on the main schema as described on the Quickstart section of this documentation at 4. Create a main schema in a new file called schema.py on my_project folder. This file can be used to merge all queries and mutations from all apps builded with django_graphbox or just add your own queries and mutations.
This package don't limit to use this basic operations. Custom operations can be defined on classic style of Graphene and Graphene-Django and finally can be merged on the main schema as described on the Quickstart section of this documentation at 4. Create a main schema in a new file called schema.py on myproject folder. This file can be used to merge all queries and mutations from all apps builded with django_graphbox or just add your own queries and mutations.

See the API REFERENCE at <https://90horasporsemana.com/graphbox/>

Expand All @@ -39,12 +39,12 @@ Use this guide to get started with the GraphBox.
1. Create a new Django project.
> ``` bash
> $ django-admin startproject my_project
> $ cd my_project
> $ python manage.py startapp my_app
> $ django-admin startproject myproject
> $ cd myproject
> $ python manage.py startapp myapp
> ```
2. Define your Django models in the my_app app.
2. Define your Django models in the myapp app.
> ``` python3
> from django.db import models
Expand All @@ -54,17 +54,17 @@ Use this guide to get started with the GraphBox.
> ```
>
> ``` bash
> $ python manage.py makemigrations my_app
> $ python manage.py makemigrations myapp
> $ python manage.py migrate
> ```
3. Configure and Build your GraphQL schema with
django_graphbox.builder.SchemaBuilder on a new file called
schema.py on the my_app app.
schema.py on the myapp app.
> ``` python3
> from django_graphbox.builder import SchemaBuilder
> from my_app.models import MyModel
> from myapp.models import MyModel
>
> builder = SchemaBuilder()
> builder.add_model(MyModel)
Expand All @@ -73,13 +73,13 @@ Use this guide to get started with the GraphBox.
> ```
4. Create a main schema in a new file called schema.py on
my_project folder. This file can be used to merge all
myproject folder. This file can be used to merge all
queries and mutations from all apps builded with django_graphbox or
just add your own queries and mutations.
> ``` python3
> import graphene
> from my_app.schema import query_class, mutation_class
> from myapp.schema import query_class, mutation_class
>
> class Query(query_class, graphene.ObjectType):
> pass
Expand Down Expand Up @@ -164,24 +164,24 @@ GraphQL API.
> permission ROLE_LEVEL_2 and ROLE_LEVEL_3.
3. Create a new instance of the SessionManager on your
schema.py file on the my_app app and
schema.py file on the myapp app and
configure the user model.
> ``` python3
> from django_graphbox.session import Manager as SessionManager
> from my_app.models import User
> from myapp.models import User
> from django.conf import settings
>
> session_manager = SessionManager(User, rol_field_name='role', login_id_field_name='custom_uname', password_field_name='custom_pwd', active_field_name='custom_active', groups=settings.ACCESS_GROUPS, modify_permissions=settings.MODIFY_PERMISSIONS)
> ```
4. Configure and Build your GraphQL schema with
django_graphbox.builder.SchemaBuilder on the file called
schema.py on the my_app app.
schema.py on the myapp app.
> ``` python3
> from django_graphbox.builder import SchemaBuilder
> from my_app.models import MyModel
> from myapp.models import MyModel
>
> # Add the SessionManager to the SchemaBuilder
> builder = SchemaBuilder(session_manager=session_manager)
Expand All @@ -201,13 +201,13 @@ GraphQL API.
> ```
5. Create a main schema in a new file called schema.py on
my_project folder. This file can be used to merge all
myproject folder. This file can be used to merge all
queries and mutations from all apps builded with django_graphbox or
just add your own queries and mutations.
> ``` python3
> import graphene
> from my_app.schema import query_class, mutation_class, session_query, session_mutation
> from myapp.schema import query_class, mutation_class, session_query, session_mutation
>
> class Query(query_class, session_query, graphene.ObjectType):
> pass
Expand Down Expand Up @@ -449,4 +449,7 @@ Some of the extra features are:
> - Version 1.0.0 to 1.1.5 was a package developed for a specific project, and the code was not published on GitHub. The code was refactored and published on GitHub on version 1.2.0.
> - Version 1.2.3 add support to set custom attributes on the model Type and set custom ordering field for the queries.
> - Version 1.2.4 Fix custom attributes on the model Type.
> - Version 1.2.5 Add support to select the operations to build for the model. You can select between field_by_id, list_field, create_field, update_field and delete_field operations. By default all operations are selected.
> - Version 1.2.5 Add support to select the operations to build for the model. You can select between field_by_id, list_field, create_field, update_field and delete_field operations. By default all operations are selected.
>- Version 1.2.7 Add support for Google Login using OAuth 2.0 with OpenID Connect.
>- Version 1.2.8 Optimize optional dependencies.
>- Version 1.2.9 Fix bug on Django auditor logs integration.
39 changes: 21 additions & 18 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
About Django GraphBox
-----------------------------------------------
---------------------------------------------------------------------------------------
Django GraphBox is a package for easy building GraphQL APIs with Django. This package is based on Graphene and Graphene-Django.

It provides a SchemaBuilder that can be used to build a GraphQL schema from Django models. It also provides a SessionManager that can be used to manage access to the GraphQL API.
Expand All @@ -22,7 +22,7 @@ When the SessionManager is used, the operations related to authentication are:
- social_login (Mutation)
- actual_user (Query)

This package don't limit to use this basic operations. Custom operations can be defined on classic style of Graphene and Graphene-Django and finally can be merged on the main schema as described on the Quickstart section of this documentation at 4. Create a main schema in a new file called schema.py on my_project folder. This file can be used to merge all queries and mutations from all apps builded with django_graphbox or just add your own queries and mutations.
This package don't limit to use this basic operations. Custom operations can be defined on classic style of Graphene and Graphene-Django and finally can be merged on the main schema as described on the Quickstart section of this documentation at 4. Create a main schema in a new file called schema.py on myproject folder. This file can be used to merge all queries and mutations from all apps builded with django_graphbox or just add your own queries and mutations.

See the full documentation at https://90horasporsemana.com/graphbox/

Expand All @@ -41,11 +41,11 @@ Use this guide to get started with the GraphBox.

.. code-block:: bash
$ django-admin startproject my_project
$ cd my_project
$ python manage.py startapp my_app
$ django-admin startproject myproject
$ cd myproject
$ python manage.py startapp myapp
2. Define your Django models in the `my_app` app.
2. Define your Django models in the `myapp` app.

.. code-block:: python3
Expand All @@ -55,27 +55,27 @@ Use this guide to get started with the GraphBox.
...
.. code-block:: bash
$ python manage.py makemigrations my_app
$ python manage.py makemigrations myapp
$ python manage.py migrate
3. Configure and Build your GraphQL schema with django_graphbox.builder.SchemaBuilder on a new file called `schema.py` on the `my_app` app.
3. Configure and Build your GraphQL schema with django_graphbox.builder.SchemaBuilder on a new file called `schema.py` on the `myapp` app.

.. code-block:: python3
from django_graphbox.builder import SchemaBuilder
from my_app.models import MyModel
from myapp.models import MyModel
builder = SchemaBuilder()
builder.add_model(MyModel)
query_class = builder.build_schema_query()
mutation_class = builder.build_schema_mutation()
4. Create a main schema in a new file called `schema.py` on `my_project` folder. This file can be used to merge all queries and mutations from all apps builded with django_graphbox or just add your own queries and mutations.
4. Create a main schema in a new file called `schema.py` on `myproject` folder. This file can be used to merge all queries and mutations from all apps builded with django_graphbox or just add your own queries and mutations.

.. code-block:: python3
import graphene
from my_app.schema import query_class, mutation_class
from myapp.schema import query_class, mutation_class
class Query(query_class, graphene.ObjectType):
pass
Expand Down Expand Up @@ -150,22 +150,22 @@ Follow the steps below to create a new user and Manage the access to the GraphQL
This permissions are related with the operations of the user model used on SessionManager. A user with the permission ROLE_LEVEL_2 only can create, update and delete user instances with the permission ROLE_LEVEL_2 and ROLE_LEVEL_3.

3. Create a new instance of the SessionManager on your `schema.py` file on the `my_app` app and configure the user model.
3. Create a new instance of the SessionManager on your `schema.py` file on the `myapp` app and configure the user model.

.. code-block:: python3
from django_graphbox.session import Manager as SessionManager
from my_app.models import User
from myapp.models import User
from django.conf import settings
session_manager = SessionManager(User, rol_field_name='role', login_id_field_name='custom_uname', password_field_name='custom_pwd', active_field_name='custom_active', groups=settings.ACCESS_GROUPS, modify_permissions=settings.MODIFY_PERMISSIONS)
4. Configure and Build your GraphQL schema with django_graphbox.builder.SchemaBuilder on the file called `schema.py` on the `my_app` app.
4. Configure and Build your GraphQL schema with django_graphbox.builder.SchemaBuilder on the file called `schema.py` on the `myapp` app.

.. code-block:: python3
from django_graphbox.builder import SchemaBuilder
from my_app.models import MyModel
from myapp.models import MyModel
# Add the SessionManager to the SchemaBuilder
builder = SchemaBuilder(session_manager=session_manager)
Expand All @@ -183,12 +183,12 @@ Follow the steps below to create a new user and Manage the access to the GraphQL
# Build your session operations
session_query, session_mutation = builder.build_session_schema()
5. Create a main schema in a new file called `schema.py` on `my_project` folder. This file can be used to merge all queries and mutations from all apps builded with django_graphbox or just add your own queries and mutations.
5. Create a main schema in a new file called `schema.py` on `myproject` folder. This file can be used to merge all queries and mutations from all apps builded with django_graphbox or just add your own queries and mutations.

.. code-block:: python3
import graphene
from my_app.schema import query_class, mutation_class, session_query, session_mutation
from myapp.schema import query_class, mutation_class, session_query, session_mutation
class Query(query_class, session_query, graphene.ObjectType):
pass
Expand Down Expand Up @@ -336,4 +336,7 @@ Release Notes
* Version 1.0.0 to 1.1.5 was a package developed for a specific project, and the code was not published on GitHub. The code was refactored and published on GitHub on version 1.2.0.
* Version 1.2.3 add support to set custom attributes on the model Type and set custom ordering field for the queries.
* Version 1.2.4 Fix custom attributes on the model Type.
* Version 1.2.5 Add support to select the operations to build for the model. You can select between field_by_id, list_field, create_field, update_field and delete_field operations. By default all operations are selected.
* Version 1.2.5 and 1.2.6 Add support to select the operations to build for the model. You can select between field_by_id, list_field, create_field, update_field and delete_field operations. By default all operations are selected.
* Version 1.2.7 Add support for Google Login using OAuth 2.0 with OpenID Connect.
* Version 1.2.8 Optimize optional dependencies.
* Version 1.2.9 Fix bug on Django auditor logs integration.
5 changes: 4 additions & 1 deletion example/example/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
from graphene_file_upload.django import FileUploadGraphQLView
try:
from graphene_file_upload.django import FileUploadGraphQLView as FileUploadGraphQLView
except:
from graphene_django.views import GraphQLView as FileUploadGraphQLView
from django.views.decorators.csrf import csrf_exempt
from .schema import schema

Expand Down
4 changes: 1 addition & 3 deletions example/prueba/schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# django_graphbox imports.
from django_graphbox.builder import SchemaBuilder
from django_graphbox.session import Manager as SessionManager
import graphene
# models imports.
from .models import *
# settings imports.
Expand Down Expand Up @@ -35,11 +34,10 @@
)
builder.add_model(
RelatedModel,
access_group=settings.GROUP_RESPONSABLE,
access_group=settings.GROUP_AUXILIAR,
)
builder.add_model(
Prueba,
access_group=settings.GROUP_AUXILIAR,
)
# build session schema
session_query, session_mutation = builder.build_session_schema()
Expand Down
16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
setuptools==62.3.2
django>=2.2.1,<=3.2.13
graphene-django==2.15.0
graphene-file-upload==1.2.2
django>=2.2.1,<=4.2.6
graphene-django>=2.15.0
# graphene-file-upload>=1.2.2 (Optional for file upload)
pyjwt==2.3.0
urllib3==1.26.9
pillow==8.4.0
facebook-sdk==3.1.0
google-auth==1.6.3
moodlepy==0.22.2
django-auditor-logs==1.0.1
django-extensions==3.1.3
facebook-sdk>=3.1.0
google-auth>=1.6.3
# moodlepy==0.22.2 (Optional for moodle integration)
# django-auditor-logs==1.0.3 (Optional for automatic audit logs)
# django-extensions==3.1.3 ( Enable only for development)
8 changes: 3 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = django_graphbox
version = 1.2.6
version = 1.2.9
description = Package for easy building GraphQL API with Django
long_description = file:docs/source/quickstart.rst
url = https://github.com/yefeza/django-graphbox
Expand All @@ -21,15 +21,13 @@ package_dir=
packages=find:
python_requires = >=3.6
install_requires =
Django >= 2.2.1
Django >= 2.2.1,<=4.2.6
graphene-django >= 2.15.0
graphene-file-upload >= 1.2.2
pyjwt >= 2.3.0
urllib3 >= 1.26.9
pillow >= 8.4.0
facebook-sdk >= 3.1.0
google-auth >= 1.6.3
moodlepy >= 0.22.2


[options.packages.find]
where=src
12 changes: 9 additions & 3 deletions src/django_graphbox/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
Global constants for the django_graphbox schema.
"""
import graphene
import graphene_file_upload.scalars
GRAPHBOX_SUPPORT_FILE_UPLOAD = False
try:
import graphene_file_upload.scalars
GRAPHBOX_SUPPORT_FILE_UPLOAD = True
except:
pass

MODEL_FIELD_TO_GRAPHENE_TYPE = {
'AutoField': graphene.ID,
Expand All @@ -15,10 +20,8 @@
'DecimalField': graphene.Decimal,
'DurationField': graphene.String,
'EmailField': graphene.String,
'FileField': graphene_file_upload.scalars.Upload,
'FilePathField': graphene.String,
'FloatField': graphene.Float,
'ImageField': graphene_file_upload.scalars.Upload,
'IntegerField': graphene.Int,
'GenericIPAddressField': graphene.String,
'PositiveIntegerField': graphene.Int,
Expand All @@ -33,6 +36,9 @@
'JSONField': graphene.String,
'OneToOneField': graphene.ID,
}
if GRAPHBOX_SUPPORT_FILE_UPLOAD:
MODEL_FIELD_TO_GRAPHENE_TYPE['FileField']=graphene_file_upload.scalars.Upload
MODEL_FIELD_TO_GRAPHENE_TYPE['ImageField']=graphene_file_upload.scalars.Upload

NO_ERROR=0
UNKNOWN_ERROR=1
Expand Down
8 changes: 6 additions & 2 deletions src/django_graphbox/helpers/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from django.contrib.auth.hashers import make_password
# pillow import
from PIL import Image
# json
import json
# logging
import logging

# Arguments class Builders

Expand Down Expand Up @@ -46,6 +46,10 @@ class Arguments:
if field.null:
required=False
setattr(Arguments, field.name.lower(), argument_type(required=required))
else:
if field_type in ['FileField', 'ImageField']:

logging.warning(f'Please install graphene-file-upload to support {field_type} fields. {field.name} on {model.__name__} will be ignored')
return Arguments

def update_arguments_class(model, fields_to_ignore=[], fields_as_password=[]):
Expand Down
Loading

0 comments on commit 9332455

Please sign in to comment.