mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-10-31 16:07:27 +03:00 
			
		
		
		
	Added test for with_context on connectionfield
This commit is contained in:
		
							parent
							
								
									7a5ad21b98
								
							
						
					
					
						commit
						e897efb79f
					
				|  | @ -37,15 +37,57 @@ class Query(graphene.ObjectType): | ||||||
|     all_my_nodes = relay.ConnectionField( |     all_my_nodes = relay.ConnectionField( | ||||||
|         MyNode, connection_type=MyConnection, customArg=graphene.String()) |         MyNode, connection_type=MyConnection, customArg=graphene.String()) | ||||||
|      |      | ||||||
|  |     context_nodes = relay.ConnectionField( | ||||||
|  |         MyNode, connection_type=MyConnection, customArg=graphene.String()) | ||||||
|  | 
 | ||||||
|     def resolve_all_my_nodes(self, args, info): |     def resolve_all_my_nodes(self, args, info): | ||||||
|         custom_arg = args.get('customArg') |         custom_arg = args.get('customArg') | ||||||
|         assert custom_arg == "1" |         assert custom_arg == "1" | ||||||
|         return [MyNode(name='my')] |         return [MyNode(name='my')] | ||||||
|      |      | ||||||
|  |     @with_context | ||||||
|  |     def resolve_context_nodes(self, args, context, info): | ||||||
|  |         custom_arg = args.get('customArg') | ||||||
|  |         assert custom_arg == "1" | ||||||
|  |         return [MyNode(name='my')] | ||||||
|  | 
 | ||||||
| schema.query = Query | schema.query = Query | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_nodefield_query(): | def test_nodefield_query(): | ||||||
|  |     query = ''' | ||||||
|  |     query RebelsShipsQuery { | ||||||
|  |       contextNodes (customArg:"1") { | ||||||
|  |         edges { | ||||||
|  |           node { | ||||||
|  |             name | ||||||
|  |           } | ||||||
|  |         }, | ||||||
|  |         myCustomField | ||||||
|  |         pageInfo { | ||||||
|  |           hasNextPage | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     ''' | ||||||
|  |     expected = { | ||||||
|  |         'allMyNodes': { | ||||||
|  |             'edges': [{ | ||||||
|  |                 'node': { | ||||||
|  |                     'name': 'my' | ||||||
|  |                 } | ||||||
|  |             }], | ||||||
|  |             'myCustomField': 'Custom', | ||||||
|  |             'pageInfo': { | ||||||
|  |                 'hasNextPage': False, | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     result = schema.execute(query) | ||||||
|  |     assert not result.errors | ||||||
|  |     assert result.data == expected | ||||||
|  | 
 | ||||||
|  | def test_connectionfield_context_query(): | ||||||
|     query = ''' |     query = ''' | ||||||
|     query RebelsShipsQuery { |     query RebelsShipsQuery { | ||||||
|       myNode(id:"TXlOb2RlOjE=") { |       myNode(id:"TXlOb2RlOjE=") { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user