Guest User

Untitled

a guest
Oct 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. class category(models.Model):
  2. QUESTION = 'Q'
  3. SOLUTION = 'S'
  4. UNKNOWN = 'U'
  5. CATEGORY_CHOICE = (
  6. ('quiz', (
  7. (QUESTION, 'Question'),
  8. (SOLUTION, 'Solution'),
  9. )
  10. ),
  11. (UNKNOWN, 'Unknown'),
  12. )
  13. name = models.CharField(max_length=1, choices=CATEGORY_CHOICE)
  14. image = models.ImageField(upload_to='uploads/category/', default='anonymous.jpg')
  15.  
  16. class Query(graphene.AbstractType):
  17. category = graphene.Field(categoryType, id=graphene.Int())
  18. def resolve_category(self, info, **kwargs):
  19. id = kwargs.get('id')
  20. if id is not None:
  21. return models.category.objects.get(pk=id)
  22. return None
  23.  
  24. class Query(graphene.ObjectType, schema.Query):
  25. pass
  26.  
  27.  
  28. schema = graphene.Schema(query=Query)
  29.  
  30. query{
  31. category(id: 1){
  32. id
  33. }
  34. }
  35.  
  36. {
  37. "errors": [
  38. {
  39. "locations": [
  40. {
  41. "line": 2,
  42. "column": 3
  43. }
  44. ],
  45. "message": "resolve_category() takes 2 positional arguments but 4 were given"
  46. }
  47. ],
  48. "data": {
  49. "category": null
  50. }
  51. }
Add Comment
Please, Sign In to add comment