@@ -7,16 +7,12 @@ Epoxy is a magical tool for rapid development of GraphQL types, schemas, resolve
77* ** Quick** : Once you create your schema, epoxy doesn't get in the way. Your resolvers will be called directly by
88` graphql-core ` with no additional indirection.
99
10- This codebase is currently a ** WORK IN PROGRESS** , and is currently at alpha stages. The API may change without notice.
11- If you're looking for a more stable pythonic ` graphql-core ` wrapper, check out
12- [ ` graphene ` ] ( https://github.com/graphql-python/graphene ) .
13-
1410## Installation
1511
1612Epoxy is available on pypi under the package name ` graphql-epoxy ` , you can get it by running:
1713
1814``` sh
19- pip install graphql-epoxy==0.1a0
15+ pip install graphql-epoxy
2016```
2117
2218## Usage
@@ -164,6 +160,99 @@ class RealHumanBean(models.Model):
164160R.Human.CanBe(Human)
165161```
166162
163+
164+ # # Mutations
165+
166+ Epoxy also supports defining mutations. Making a Mutation a Relay mutation is as simple as changing `R.Mutation` to
167+ `Relay.Mutation` .
168+
169+
170+ ```python
171+
172+ class AddFriend(R.Mutation):
173+ class Input:
174+ human_to_add = R.ID .NonNull
175+
176+ class Output:
177+ new_friends_list = R.Human.List
178+
179+ @ R.resolve_with_args
180+ def resolve(self , obj, human_to_add):
181+ obj.add_friend(human_to_add)
182+ return self .Output(new_friends_list = obj.friends)
183+
184+
185+ schema = R.schema(R.Query, R.Mutations)
186+
187+ ```
188+
189+ You can then execute the query:
190+
191+
192+ ```graphql
193+ mutation AddFriend {
194+ addFriend(input : {humanToAdd: 6 }) {
195+ newFriendsList {
196+ id
197+ name
198+ homePlanet
199+ }
200+ }
201+ }
202+ ```
203+
204+ # # Defining custom scalar types:
205+
206+
207+ ```python
208+ class DateTime(R.Scalar):
209+ @ staticmethod
210+ def serialize(dt):
211+ return dt.isoformat()
212+
213+ @ staticmethod
214+ def parse_literal(node):
215+ if isinstance (node, ast.StringValue):
216+ return datetime.datetime.strptime(node.value, " %Y-%m-%d T%H:%M:%S.%f " )
217+
218+ @ staticmethod
219+ def parse_value(value):
220+ return datetime.datetime.strptime(value, " %Y-%m-%d T%H:%M:%S.%f " )
221+
222+ ```
223+
224+ # # Defining input types:
225+
226+ ```python
227+ class SimpleInput(R.InputType):
228+ a = R.Int
229+ b = R.Int
230+ some_underscore = R.String
231+ some_from_field = R.String(default_value = ' Hello World' )
232+
233+ ```
234+
235+ # # Defining an Enum (using `enum` module)
236+
237+ ```python
238+
239+ from enum import Enum
240+
241+ @ R
242+ class MyEnum(Enum):
243+ FOO = 1
244+ BAR = 2
245+ BAZ = 3
246+
247+ ```
248+
249+ # ## Starwars?!
250+ Use the force, check out how we' ve defined the
251+ [schema](https:// github.com/ graphql- python/ graphql- epoxy/ blob/ master/ tests/ test_starwars/ schema.py)
252+ for the starwars tests, and compare them to the reference implementation' s
253+ [schema](https:// github.com/ graphql/ graphql- js/ blob/ master/ src/ __tests__/ starWarsSchema.js).
254+
255+
167256# # Relay Support
168257
169258At this point, Epoxy has rudimentary `relay` support. Enable support for `Relay` by mixing in the `RelayMixin` using
@@ -264,50 +353,3 @@ result = graphql(Schema, '''
264353}
265354''' )
266355```
267-
268-
269- # # Mutations
270-
271- Epoxy also supports defining mutations. Making a Mutation a Relay mutation is as simple as changing `R.Mutation` to
272- `Relay.Mutation` .
273-
274-
275- ```python
276-
277- class AddFriend(R.Mutation):
278- class Input:
279- human_to_add = R.ID .NonNull
280-
281- class Output:
282- new_friends_list = R.Human.List
283-
284- @ R.resolve_with_args
285- def resolve(self , obj, human_to_add):
286- obj.add_friend(human_to_add)
287- return self .Output(new_friends_list = obj.friends)
288-
289-
290- schema = R.schema(R.Query, R.Mutations)
291-
292- ```
293-
294- You can then execute the query:
295-
296-
297- ```graphql
298- mutation AddFriend {
299- addFriend(input : {humanToAdd: 6 }) {
300- newFriendsList {
301- id
302- name
303- homePlanet
304- }
305- }
306- }
307- ```
308-
309-
310-
311-
312-
313-
0 commit comments