Skip to content

Commit

Permalink
Added context example
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Nov 12, 2016
1 parent 6c7cd4e commit b1bffc4
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/context_example.py
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,39 @@
import graphene


class User(graphene.ObjectType):
id = graphene.ID()
name = graphene.String()


class Query(graphene.ObjectType):
me = graphene.Field(User)

def resolve_me(self, args, context, info):
return context['user']

schema = graphene.Schema(query=Query)
query = '''
query something{
me {
id
name
}
}
'''


def test_query():
result = schema.execute(query, context_value={'user': User(id='1', name='Syrus')})
assert not result.errors
assert result.data == {
'me': {
'id': '1',
'name': 'Syrus',
}
}


if __name__ == '__main__':
result = schema.execute(query, context_value={'user': User(id='X', name='Console')})
print(result.data['me'])

0 comments on commit b1bffc4

Please sign in to comment.