def test_accepts_multiple_subscription_fields_defined_in_schema(): SubscriptionTypeMultiple = GraphQLObjectType( name='Subscription', fields=OrderedDict([ ('importantEmail', GraphQLField(EmailEventType)), ('nonImportantEmail', GraphQLField(EmailEventType)), ])) test_schema = GraphQLSchema(query=QueryType, subscription=SubscriptionTypeMultiple) stream = AsyncSingleStream() send_important_email, subscription = create_subscription( stream, test_schema) email = Email( from_='*****@*****.**', subject='Alright', message='Tests are good', unread=True, ) l = [] fut1 = asyncio.ensure_future(p_subscribe(l, stream)) fut2 = asyncio.ensure_future(send_important_email(email)) asyncio.get_event_loop().run_until_complete(asyncio.gather(fut1, fut2)) assert l[0][0] == email
def __init__(self): super().__init__() self.configure_proc = None self.shutdown_command = { "running": False, "uptime": None, "stdout": None, "stderror": None, "returncode": None, } self.shutdown_command_type = GraphQLObjectType( "MaverickShutdown", lambda: { "running": GraphQLField(GraphQLBoolean, description=""), "uptime": GraphQLField( GraphQLInt, description= "Number of seconds the process has been running for", ), "terminate": GraphQLField(GraphQLBoolean, description=""), "stdout": GraphQLField(GraphQLString, description=""), "stderror": GraphQLField(GraphQLString, description=""), "returncode": GraphQLField(GraphQLInt, description=""), }, description="Maverick shutdown interface", ) self.q = { "MaverickShutdown": GraphQLField(self.shutdown_command_type, resolve=self.get_shutdown_command_status) } self.m = { "MaverickShutdown": GraphQLField( self.shutdown_command_type, args=self.get_mutation_args(self.shutdown_command_type), resolve=self.run_shutdown_command, ) } self.s = { "MaverickShutdown": GraphQLField( self.shutdown_command_type, subscribe=self.sub_shutdown_command_status, resolve=None, ) }
def resolve(self, next, root, info, **args): if ( info.field_name == '__schema' or info.field_name == '_debug' ): from user.models import User from django.conf import settings if ( settings.DEBUG or ( hasattr(info.context, 'user') and info.context.user and info.context.user.is_staff ) or ( hasattr(info.context, "userID") and info.context.userID is not None and User.objects.get(id=info.context.userID).is_staff ) ): return next(root, info, **args) from graphql import GraphQLObjectType, GraphQLField, GraphQLSchema, GraphQLString query = GraphQLObjectType( "Query", lambda: { "mohanlal": GraphQLField( GraphQLString, description='Sawari Giri Giri...', resolver=lambda *_: "Sawari Giri Giri..." ), "rajnikath": GraphQLField( GraphQLString, description='Naan solrathaiyum seiven, sollathathiyum seiven', resolver=lambda *_: "Naan solrathaiyum seiven, sollathathiyum seiven" ), "amitabhBachhan": GraphQLField( GraphQLString, description='Don ko pakadna mushkil hi nahin, naamumkin hai', resolver=lambda *_: "Don ko pakadna mushkil hi nahin, naamumkin hai" ), "tonyStark": GraphQLField( GraphQLString, description='I know exactly what I am doing', resolver=lambda *_: "I know exactly what I am doing" ), } ) info.schema = GraphQLSchema(query=query) return next(root, info, **args) return next(root, info, **args)