def test_throws_when_given_empty_types(): incomplete_introspection = { '__schema': { 'queryType': {'name': 'QueryType'}, 'types': [] } } with raises(Exception) as excinfo: build_client_schema(incomplete_introspection) assert str(excinfo.value) == 'Invalid or incomplete schema, unknown type: QueryType. Ensure that a full ' \ 'introspection query is used in order to build a client schema.'
def _test_schema(server_schema): initial_introspection = graphql(server_schema, introspection_query) client_schema = build_client_schema(initial_introspection.data) second_introspection = graphql(client_schema, introspection_query) assert initial_introspection.data == second_introspection.data return client_schema
def test_cannot_use_client_schema_for_general_execution(): customScalar = GraphQLScalarType(name='CustomScalar', serialize=lambda: None) schema = GraphQLSchema(query=GraphQLObjectType( name='Query', fields={ 'foo': GraphQLField(GraphQLString, args=OrderedDict([('custom1', GraphQLArgument(customScalar)), ('custom2', GraphQLArgument(customScalar))])) })) introspection = graphql(schema, introspection_query) client_schema = build_client_schema(introspection.data) class data: foo = 'bar' result = graphql( client_schema, 'query NoNo($v: CustomScalar) { foo(custom1: 123, custom2: $v) }', data, {'v': 'baz'}) assert result.data == {'foo': None} assert [format_error(e) for e in result.errors] == [{ 'locations': [{ 'column': 32, 'line': 1 }], 'message': 'Client Schema cannot be used for execution.' }]
def test_fails_on_a_deep_non_null(): schema = GraphQLSchema(query=GraphQLObjectType( name='Query', fields={ 'foo': GraphQLField( GraphQLList( GraphQLList(GraphQLList(GraphQLNonNull(GraphQLString))))) })) introspection = graphql(schema, introspection_query) with raises(Exception) as excinfo: build_client_schema(introspection.data) assert str( excinfo.value) == 'Decorated type deeper than introspection query.'
def test_fails_on_a_deep_non_null(): schema = GraphQLSchema( query=GraphQLObjectType( name='Query', fields={ 'foo': GraphQLField( GraphQLList(GraphQLList(GraphQLList(GraphQLNonNull(GraphQLString)))) ) } ) ) introspection = graphql(schema, introspection_query) with raises(Exception) as excinfo: build_client_schema(introspection.data) assert str(excinfo.value) == 'Decorated type deeper than introspection query.'
def test_cannot_use_client_schema_for_general_execution(): customScalar = GraphQLScalarType( name='CustomScalar', serialize=lambda: None ) schema = GraphQLSchema( query=GraphQLObjectType( name='Query', fields={ 'foo': GraphQLField( GraphQLString, args=OrderedDict([ ('custom1', GraphQLArgument(customScalar)), ('custom2', GraphQLArgument(customScalar)) ]) ) } ) ) introspection = graphql(schema, introspection_query) client_schema = build_client_schema(introspection.data) class data: foo = 'bar' result = graphql( client_schema, 'query NoNo($v: CustomScalar) { foo(custom1: 123, custom2: $v) }', data, {'v': 'baz'} ) assert result.data == {'foo': None} assert [format_error(e) for e in result.errors] == [ {'locations': [{'column': 32, 'line': 1}], 'message': 'Client Schema cannot be used for execution.'} ]