<s> from collections import namedtuple <EOL> from pytest import raises <EOL> from graphql . core import graphql <EOL> from graphql . core . type import ( <EOL> GraphQLSchema , <EOL> GraphQLObjectType , <EOL> GraphQLField , <EOL> GraphQLArgument , <EOL> GraphQLList , <EOL> GraphQLNonNull , <EOL> GraphQLInt , <EOL> GraphQLString , <EOL> GraphQLBoolean , <EOL> GraphQLID , <EOL> ) <EOL> from graphql_relay . connection . arrayconnection import connection_from_list <EOL> from graphql_relay . connection . connection import ( <EOL> connection_args , <EOL> connection_definitions <EOL> ) <EOL> User = namedtuple ( '<STR_LIT>' , [ '<STR_LIT:name>' ] ) <EOL> allUsers = [ <EOL> User ( name = '<STR_LIT>' ) , <EOL> User ( name = '<STR_LIT>' ) , <EOL> User ( name = '<STR_LIT>' ) , <EOL> User ( name = '<STR_LIT>' ) , <EOL> User ( name = '<STR_LIT>' ) , <EOL> ] <EOL> userType = GraphQLObjectType ( <EOL> '<STR_LIT>' , <EOL> fields = lambda : { <EOL> '<STR_LIT:name>' : GraphQLField ( GraphQLString ) , <EOL> '<STR_LIT>' : GraphQLField ( <EOL> friendConnection , <EOL> args = connection_args , <EOL> resolver = lambda user , args , * <EOL> _ : connection_from_list ( allUsers , args ) , <EOL> ) , <EOL> } , <EOL> ) <EOL> friendConnection = connection_definitions ( <EOL> '<STR_LIT>' , <EOL> userType , <EOL> edge_fields = lambda : { <EOL> '<STR_LIT>' : GraphQLField ( <EOL> GraphQLString , <EOL> resolver = lambda * _ : '<STR_LIT>' <EOL> ) , <EOL> } , <EOL> connection_fields = lambda : { <EOL> '<STR_LIT>' : GraphQLField ( <EOL> GraphQLInt , <EOL> resolver = lambda * _ : len ( allUsers ) <EOL> ) , <EOL> } <EOL> ) . connection_type <EOL> queryType = GraphQLObjectType ( <EOL> '<STR_LIT>' , <EOL> fields = lambda : { <EOL> '<STR_LIT:user>' : GraphQLField ( <EOL> userType , <EOL> resolver = lambda * _ : allUsers [ <NUM_LIT:0> ] <EOL> ) , <EOL> } <EOL> ) <EOL> schema = GraphQLSchema ( query = queryType ) <EOL> def test_include_connections_and_edge_types ( ) : <EOL> query = '''<STR_LIT>''' <EOL> expected = { <EOL> '<STR_LIT:user>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> ] <EOL> } <EOL> } <EOL> } <EOL> result = graphql ( schema , query ) <EOL> assert not result . errors <EOL> assert result . data == expected </s>
