Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. from graphql.core import graphql
  2. from graphql.core.type import (
  3. GraphQLObjectType,
  4. GraphQLField,
  5. GraphQLString,
  6. )
  7.  
  8. humanType = GraphQLObjectType(
  9. 'Human',
  10. description='A humanoid creature in the Star Wars universe.',
  11. fields=lambda: {
  12. 'id': GraphQLField(
  13. GraphQLNonNull(GraphQLString),
  14. resolver=lambda human, *_: 'random id',
  15. ),
  16. 'name': GraphQLField(
  17. GraphQLString,
  18. resolver=lambda human, *_: 'random name',
  19. ),
  20. },
  21. )
  22.  
  23.  
  24. StarWarsSchema = GraphQLSchema(query=humanType)
  25.  
  26. query = '''
  27. query HeroNameQuery {
  28. id
  29. name
  30. }
  31. '''
  32. expected = {
  33. 'name': 'random name',
  34. 'id': 'random id',
  35. }
  36. result = graphql(StarWarsSchema, query)
  37. # assert not result.errors
  38. # assert result.data.keys() == ['id','name']
  39. print result.data
  40.  
  41. # Result.data should be {'name': 'random name', 'id': 'random id'}
  42. # Instead of {'id': 'random id', 'name': 'random name'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement