def document_from_string(self, schema, document_string): """Parse string and setup request document for execution. Args: schema (graphql.GraphQLSchema): Schema definition object document_string (str): Request query/mutation/subscription document. Returns: graphql.GraphQLDocument """ if isinstance(document_string, ast.Document): document_ast = document_string document_string = print_ast(document_ast) else: if not isinstance(document_string, str): logger.error("The query must be a string") document_ast = parse(document_string) return GraphQLDocument( schema=schema, document_string=document_string, document_ast=document_ast, execute=partial(execute_and_validate_and_strip, schema, document_ast, **self.execute_params), )
async def mutator(self, info: 'ResolveInfo', command: str, w_args: Dict[str, Any], _kwargs: Dict[str, Any], _meta: Dict[str, Any]) -> List[Dict[str, Any]]: """Mutate workflow.""" req_meta = { 'auth_user': info.context.get( # type: ignore[union-attr] 'current_user', 'unknown user') } w_ids = [ flow[WORKFLOW].id for flow in await self.get_workflows_data(w_args) ] if not w_ids: return [{'response': (False, 'No matching workflows')}] # Pass the request to the workflow GraphQL endpoints _, variables, _, _ = info.context.get( # type: ignore[union-attr] 'graphql_params') # Create a modified request string, # containing only the current mutation/field. operation_ast = deepcopy(info.operation) operation_ast.selection_set.selections = info.field_asts graphql_args = { 'request_string': print_ast(operation_ast), 'variables': variables, } return await self.workflows_mgr.multi_request( # type: ignore # TODO 'graphql', w_ids, graphql_args, req_meta=req_meta)
async def mutator(self, info, *m_args): """Mutate workflow.""" req_meta = {} _, w_args, _, _ = m_args req_meta['auth_user'] = info.context.get( 'current_user', 'unknown user') w_ids = [ flow[WORKFLOW].id for flow in await self.get_workflows_data(w_args)] if not w_ids: return [{ 'response': (False, 'No matching workflows')}] # Pass the request to the workflow GraphQL endpoints _, variables, _, _ = info.context.get('graphql_params') # Create a modified request string, # containing only the current mutation/field. operation_ast = deepcopy(info.operation) operation_ast.selection_set.selections = info.field_asts graphql_args = { 'request_string': print_ast(operation_ast), 'variables': variables, } return await self.workflows_mgr.multi_request( 'graphql', w_ids, graphql_args, req_meta=req_meta )
def document_from_string(self, schema, document_string): # type: (GraphQLSchema, Union[Document, str]) -> GraphQLDocument if isinstance(document_string, ast.Document): document_ast = document_string document_string = print_ast(document_ast) else: assert isinstance(document_string, string_types), "The query must be a string" document_ast = parse(document_string) return GraphQLDocument( schema=schema, document_string=document_string, document_ast=document_ast, execute=partial(execute_and_validate, schema, document_ast, **self.execute_params), )