|
1 | 1 | Metadata-Version: 1.1
|
2 |
| -Name: graphene-django |
3 |
| -Version: 2.0.dev2017083101 |
4 |
| -Summary: Graphene Django integration |
5 |
| -Home-page: https://github.com/graphql-python/graphene-django |
6 |
| -Author: Syrus Akbary |
7 |
| - |
| 2 | +Name: graphene-django-extras |
| 3 | +Version: 0.0.1b8 |
| 4 | +Summary: Graphene-Django-Extras add some extra funcionalities to graphene-django to facilitate the graphql use without Relay and allow pagination and filtering integration |
| 5 | +Home-page: https://github.com/eamigo86/graphene-django-extras |
| 6 | +Author: Ernesto Perez Amigo |
| 7 | + |
8 | 8 | License: MIT
|
9 |
| -Description: Please read |
10 |
| - `UPGRADE-v1.0.md <https://github.com/graphql-python/graphene/blob/master/UPGRADE-v1.0.md>`__ |
11 |
| - to learn how to upgrade to Graphene ``1.0``. |
12 |
| - |
13 |
| - -------------- |
14 |
| - |
15 |
| - |Graphene Logo| Graphene-Django |Build Status| |PyPI version| |Coverage Status| |
16 |
| - =============================================================================== |
17 |
| - |
18 |
| - A `Django <https://www.djangoproject.com/>`__ integration for |
19 |
| - `Graphene <http://graphene-python.org/>`__. |
20 |
| - |
21 |
| - Installation |
22 |
| - ------------ |
23 |
| - |
24 |
| - For instaling graphene, just run this command in your shell |
25 |
| - |
| 9 | +Description: |
| 10 | + |
| 11 | + Graphene-Django-Extras |
| 12 | + ====================== |
| 13 | + |
| 14 | + This package add some extra functionalities to graphene-django to facilitate the graphql use without Relay and |
| 15 | + allow pagination and filtering integration. |
| 16 | + |
| 17 | + Installation: |
| 18 | + ------------- |
| 19 | + |
| 20 | + For installing graphene-django-extras, just run this command in your shell: |
| 21 | + |
26 | 22 | .. code:: bash
|
27 |
| - |
28 |
| - pip install "graphene-django>=1.0" |
29 |
| - |
30 |
| - Settings |
31 |
| - ~~~~~~~~ |
32 |
| - |
33 |
| - .. code:: python |
34 |
| - |
35 |
| - INSTALLED_APPS = ( |
36 |
| - # ... |
37 |
| - 'graphene_django', |
38 |
| - ) |
39 |
| - |
40 |
| - GRAPHENE = { |
41 |
| - 'SCHEMA': 'app.schema.schema' # Where your Graphene schema lives |
42 |
| - } |
43 |
| - |
44 |
| - Urls |
45 |
| - ~~~~ |
46 |
| - |
47 |
| - We need to set up a ``GraphQL`` endpoint in our Django app, so we can |
48 |
| - serve the queries. |
49 |
| - |
| 23 | + |
| 24 | + pip install "graphene-django-extras" |
| 25 | + |
| 26 | + Documentation: |
| 27 | + -------------- |
| 28 | + Extra functionalities: |
| 29 | + Fields: |
| 30 | + 1. DjangoFilterListField |
| 31 | + 2. DjangoFilterPaginateListField |
| 32 | + 3. DjangoListObjectField (Recommended) |
| 33 | + |
| 34 | + Mutations: |
| 35 | + 1. DjangoSerializerMutation |
| 36 | + |
| 37 | + Types: |
| 38 | + 1. DjangoObjectTypeExtra |
| 39 | + 2. DjangoListObjectType |
| 40 | + 3. DjangoInputObjectType |
| 41 | + |
| 42 | + Pagination: |
| 43 | + 1. LimitOffsetGraphqlPagination |
| 44 | + 2. PageGraphqlPagination |
| 45 | + 3. CursorGraphqlPagination (coming soon) |
| 46 | + |
| 47 | + Examples: |
| 48 | + --------- |
| 49 | + |
| 50 | + Here is a simple use of graphene-django-extras: |
| 51 | + |
| 52 | + 1- Types Definition: |
| 53 | + |
50 | 54 | .. code:: python
|
51 |
| - |
52 |
| - from django.conf.urls import url |
53 |
| - from graphene_django.views import GraphQLView |
54 |
| - |
55 |
| - urlpatterns = [ |
56 |
| - # ... |
57 |
| - url(r'^graphql', GraphQLView.as_view(graphiql=True)), |
58 |
| - ] |
59 |
| - |
60 |
| - Examples |
61 |
| - -------- |
62 |
| - |
63 |
| - Here is a simple Django model: |
64 |
| - |
| 55 | + |
| 56 | + from django.contrib.auth.models import User |
| 57 | + from graphene_django_extras import DjangoObjectType, DjangoListObjectType |
| 58 | + from graphene_django_extras.pagination import LimitOffsetGraphqlPagination |
| 59 | + |
| 60 | + class UserType(DjangoObjectType): |
| 61 | + """ |
| 62 | + This DjangoObjectType have a ID field, that allow filter by id and resolve method definition on Queries is not necessary |
| 63 | + """ |
| 64 | + |
| 65 | + class Meta: |
| 66 | + model = User |
| 67 | + description = " Type definition for single User model object " |
| 68 | + filter_fields = { |
| 69 | + 'id': ['exact', ], |
| 70 | + 'first_name': ['icontains', 'iexact'], |
| 71 | + 'last_name': ['icontains', 'iexact'], |
| 72 | + 'username': ['icontains', 'iexact'], |
| 73 | + 'email': ['icontains', 'iexact'] |
| 74 | + } |
| 75 | + |
| 76 | + class UserListType(DjangoListObjectType): |
| 77 | + class Meta: |
| 78 | + description = " Type definition for List of users " |
| 79 | + model = User |
| 80 | + pagination = LimitOffsetGraphqlPagination() |
| 81 | + |
| 82 | + |
| 83 | + 2- Input Types can be defined for use on mutations: |
| 84 | + |
65 | 85 | .. code:: python
|
66 |
| - |
67 |
| - from django.db import models |
68 |
| - |
69 |
| - class UserModel(models.Model): |
70 |
| - name = models.CharField(max_length=100) |
71 |
| - last_name = models.CharField(max_length=100) |
72 |
| - |
73 |
| - To create a GraphQL schema for it you simply have to write the |
74 |
| - following: |
75 |
| - |
| 86 | + |
| 87 | + from graphene_django_extras import DjangoInputObjectType |
| 88 | + |
| 89 | + class UserInput(DjangoInputObjectType): |
| 90 | + class Meta: |
| 91 | + description = " User Input Type for used as input on Arguments classes on traditional Mutations " |
| 92 | + model = User |
| 93 | + |
| 94 | + |
| 95 | + 3- You can define traditional mutations that use Input Types or Mutations based on DRF SerializerClass: |
| 96 | + |
76 | 97 | .. code:: python
|
77 |
| - |
78 |
| - from graphene_django import DjangoObjectType |
| 98 | + |
79 | 99 | import graphene
|
80 |
| - |
81 |
| - class User(DjangoObjectType): |
| 100 | + from .serializers import UserSerializer |
| 101 | + from graphene_django_extras import DjangoSerializerMutation |
| 102 | + from .types import UserType |
| 103 | + from .input_types import UserInputType |
| 104 | + |
| 105 | + class UserSerializerMutation(DjangoSerializerMutation): |
| 106 | + """ |
| 107 | + DjangoSerializerMutation auto implement Create, Delete and Update function |
| 108 | + """ |
| 109 | + class Meta: |
| 110 | + description = " Serializer based Mutation for Users " |
| 111 | + serializer_class = UserSerializer |
| 112 | + |
| 113 | + |
| 114 | + class UserMutation(graphene.mutation): |
| 115 | + """ |
| 116 | + To traditional graphene's mutation classes definition you must implement the mutate function |
| 117 | + """ |
| 118 | + |
| 119 | + user = graphene.Field(UserType, required=False) |
| 120 | + |
| 121 | + class Arguments: |
| 122 | + new_user = graphene.Argument(UserInput) |
| 123 | + |
82 | 124 | class Meta:
|
83 |
| - model = UserModel |
84 |
| - |
85 |
| - class Query(graphene.ObjectType): |
86 |
| - users = graphene.List(User) |
87 |
| - |
88 |
| - @graphene.resolve_only_args |
89 |
| - def resolve_users(self): |
90 |
| - return UserModel.objects.all() |
91 |
| - |
92 |
| - schema = graphene.Schema(query=Query) |
93 |
| - |
94 |
| - Then you can simply query the schema: |
95 |
| - |
| 125 | + description = " Traditional graphene mutation for Users " |
| 126 | + |
| 127 | + @classmethod |
| 128 | + def mutate(cls, info, **kwargs): |
| 129 | + ... |
| 130 | + |
| 131 | + |
| 132 | + 4- Defining schemes: |
| 133 | + |
| 134 | + .. code:: python |
| 135 | + |
| 136 | + import graphene |
| 137 | + from graphene_django_extras import DjangoObjectField, DjangoListObjectField |
| 138 | + from .types import UserType, UserListType |
| 139 | + from .mutations import UserMutation, UserSerializerMutation |
| 140 | + |
| 141 | + class Queries(graphene.ObjectType): |
| 142 | + # Possible User list queries definitions |
| 143 | + all_users = DjangoListObjectField(UserListType, description=_('All Users query')) |
| 144 | + all_users1 = DjangoFilterPaginateListField(UserType, pagination=LimitOffsetGraphqlPagination()) |
| 145 | + all_users2 = DjangoFilterListField(UserType) |
| 146 | + all_users3 = DjangoListObjectField(UserListType, filterset_class=UserFilter, description=_('All Users query')) |
| 147 | + |
| 148 | + # Defining the petition to a user |
| 149 | + user = DjangoObjectField(UserType, description=_('Only one user')) |
| 150 | + |
| 151 | + # Another way to define a single user query |
| 152 | + other_way_user = DjangoObjectField(UserListType.getOne(), description=_('User List with pagination and filtering')) |
| 153 | + |
| 154 | + class Mutations(graphene.ObjectType): |
| 155 | + user_create = UserSerializerMutation.CreateField(deprecation_reason='Deprecation message') |
| 156 | + user_delete = UserSerializerMutation.DeleteField() |
| 157 | + user_update = UserSerializerMutation.UpdateField() |
| 158 | + |
| 159 | + traditional_user_mutation = UserMutation.Field() |
| 160 | + |
| 161 | + |
| 162 | + 5- Examples of queries: |
| 163 | + |
96 | 164 | .. code:: python
|
97 |
| - |
98 |
| - query = ''' |
99 |
| - query { |
100 |
| - users { |
101 |
| - name, |
| 165 | + |
| 166 | + { |
| 167 | + allUsers(username_Icontains:"john"){ |
| 168 | + results(limit:5, offset:5){ |
| 169 | + id |
| 170 | + username |
| 171 | + firstName |
| 172 | + lastName |
| 173 | + } |
| 174 | + totalCount |
| 175 | + } |
| 176 | + |
| 177 | + allUsers1(lastName_Iexact:"Doe", limit:5, offset:0){ |
| 178 | + id |
| 179 | + username |
| 180 | + firstName |
| 181 | + lastName |
| 182 | + } |
| 183 | + |
| 184 | + allUsers2(firstName_Icontains: "J"){ |
| 185 | + id |
| 186 | + username |
| 187 | + firstName |
102 | 188 | lastName
|
103 |
| - } |
104 | 189 | }
|
105 |
| - ''' |
106 |
| - result = schema.execute(query) |
107 |
| - |
108 |
| - To learn more check out the following `examples <examples/>`__: |
109 |
| - |
110 |
| - - **Schema with Filtering**: `Cookbook example <examples/cookbook>`__ |
111 |
| - - **Relay Schema**: `Starwars Relay example <examples/starwars>`__ |
112 |
| - |
113 |
| - Contributing |
114 |
| - ------------ |
115 |
| - |
116 |
| - After cloning this repo, ensure dependencies are installed by running: |
117 |
| - |
118 |
| - .. code:: sh |
119 |
| - |
120 |
| - pip install -e ".[test]" |
121 |
| - |
122 |
| - After developing, the full test suite can be evaluated by running: |
123 |
| - |
124 |
| - .. code:: sh |
125 |
| - |
126 |
| - py.test graphene_django --cov=graphene_django # Use -v -s for verbose mode |
127 |
| - |
128 |
| - Documentation |
129 |
| - ~~~~~~~~~~~~~ |
130 |
| - |
131 |
| - The `documentation <http://docs.graphene-python.org/projects/django/en/latest/>`__ is generated using the excellent |
132 |
| - `Sphinx <http://www.sphinx-doc.org/>`__ and a custom theme. |
133 |
| - |
134 |
| - The documentation dependencies are installed by running: |
135 |
| - |
136 |
| - .. code:: sh |
137 |
| - |
138 |
| - cd docs |
139 |
| - pip install -r requirements.txt |
140 |
| - |
141 |
| - Then to produce a HTML version of the documentation: |
142 |
| - |
143 |
| - .. code:: sh |
144 |
| - |
145 |
| - make html |
146 |
| - |
147 |
| - .. |Graphene Logo| image:: http://graphene-python.org/favicon.png |
148 |
| - .. |Build Status| image:: https://travis-ci.org/graphql-python/graphene-django.svg?branch=master |
149 |
| - :target: https://travis-ci.org/graphql-python/graphene-django |
150 |
| - .. |PyPI version| image:: https://badge.fury.io/py/graphene-django.svg |
151 |
| - :target: https://badge.fury.io/py/graphene-django |
152 |
| - .. |Coverage Status| image:: https://coveralls.io/repos/graphql-python/graphene-django/badge.svg?branch=master&service=github |
153 |
| - :target: https://coveralls.io/github/graphql-python/graphene-django?branch=master |
154 |
| - |
155 |
| -Keywords: api graphql protocol rest relay graphene |
| 190 | + |
| 191 | + user(id:2){ |
| 192 | + id |
| 193 | + username |
| 194 | + firstName |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + |
| 199 | + 6- Examples of Mutations: |
| 200 | + |
| 201 | + .. code:: python |
| 202 | + |
| 203 | + mutation{ |
| 204 | + userCreate(newUser:{password:"test*123", email: " [email protected]", username:"test"}){ |
| 205 | + user{ |
| 206 | + id |
| 207 | + username |
| 208 | + firstName |
| 209 | + lastName |
| 210 | + } |
| 211 | + ok |
| 212 | + errors{ |
| 213 | + field |
| 214 | + messages |
| 215 | + } |
| 216 | + } |
| 217 | + |
| 218 | + userDelete(id:1){ |
| 219 | + ok |
| 220 | + errors{ |
| 221 | + field |
| 222 | + messages |
| 223 | + } |
| 224 | + } |
| 225 | + |
| 226 | + userUpdate(newUser:{id:1, username:"John"}){ |
| 227 | + user{ |
| 228 | + id |
| 229 | + username |
| 230 | + } |
| 231 | + ok |
| 232 | + errors{ |
| 233 | + field |
| 234 | + messages |
| 235 | + } |
| 236 | + } |
| 237 | + } |
| 238 | + |
| 239 | +Keywords: api graphql protocol rest graphene django |
156 | 240 | Platform: any
|
157 | 241 | Classifier: Development Status :: 3 - Alpha
|
158 | 242 | Classifier: Intended Audience :: Developers
|
|
0 commit comments