Exemplo n.º 1
0
def execute_query(
    handle,
    query,
    variables=None,
    pipeline_run_storage=None,
    scheduler=None,
    raise_on_error=False,
    use_sync_executor=False,
):
    check.inst_param(handle, 'handle', ExecutionTargetHandle)
    check.str_param(query, 'query')
    check.opt_dict_param(variables, 'variables')
    # We allow external creation of the pipeline_run_storage to support testing contexts where we
    # need access to the underlying run storage
    check.opt_inst_param(pipeline_run_storage, 'pipeline_run_storage', RunStorage)
    check.opt_inst_param(scheduler, 'scheduler', Scheduler)
    check.bool_param(raise_on_error, 'raise_on_error')
    check.bool_param(use_sync_executor, 'use_sync_executor')

    query = query.strip('\'" \n\t')

    execution_manager = SynchronousExecutionManager()

    pipeline_run_storage = pipeline_run_storage or InMemoryRunStorage()

    context = DagsterGraphQLContext(
        handle=handle,
        pipeline_runs=pipeline_run_storage,
        scheduler=scheduler,
        execution_manager=execution_manager,
        raise_on_error=raise_on_error,
        version=__version__,
    )

    executor = SyncExecutor() if use_sync_executor else GeventExecutor()

    result = graphql(
        request_string=query,
        schema=create_schema(),
        context=context,
        variables=variables,
        executor=executor,
    )

    result_dict = result.to_dict()

    # Here we detect if this is in fact an error response
    # If so, we iterate over the result_dict and the original result
    # which contains a GraphQLError. If that GraphQL error contains
    # an original_error property (which is the exception the resolver
    # has thrown, typically) we serialize the stack trace of that exception
    # in the 'stack_trace' property of each error to ease debugging

    if 'errors' in result_dict:
        check.invariant(len(result_dict['errors']) == len(result.errors))
        for python_error, error_dict in zip(result.errors, result_dict['errors']):
            if hasattr(python_error, 'original_error') and python_error.original_error:
                error_dict['stack_trace'] = get_stack_trace_array(python_error.original_error)

    return result_dict
Exemplo n.º 2
0
def execute_query(recon_repo,
                  query,
                  variables=None,
                  use_sync_executor=False,
                  instance=None):
    check.inst_param(recon_repo, 'recon_repo', ReconstructableRepository)
    check.str_param(query, 'query')
    check.opt_dict_param(variables, 'variables')
    instance = (check.inst_param(instance, 'instance', DagsterInstance)
                if instance else DagsterInstance.get())
    check.bool_param(use_sync_executor, 'use_sync_executor')

    query = query.strip('\'" \n\t')

    execution_manager = SubprocessExecutionManager(instance)

    context = DagsterGraphQLContext(
        environments=[
            InProcessDagsterEnvironment(
                recon_repo,
                execution_manager=execution_manager,
            )
        ],
        instance=instance,
        version=__version__,
    )

    executor = SyncExecutor() if use_sync_executor else GeventExecutor()

    result = graphql(
        request_string=query,
        schema=create_schema(),
        context_value=context,
        variable_values=variables,
        executor=executor,
    )

    result_dict = result.to_dict()

    execution_manager.join()

    # Here we detect if this is in fact an error response
    # If so, we iterate over the result_dict and the original result
    # which contains a GraphQLError. If that GraphQL error contains
    # an original_error property (which is the exception the resolver
    # has thrown, typically) we serialize the stack trace of that exception
    # in the 'stack_trace' property of each error to ease debugging

    if 'errors' in result_dict:
        check.invariant(len(result_dict['errors']) == len(result.errors))
        for python_error, error_dict in zip(result.errors,
                                            result_dict['errors']):
            if hasattr(python_error,
                       'original_error') and python_error.original_error:
                error_dict['stack_trace'] = get_stack_trace_array(
                    python_error.original_error)

    return result_dict
Exemplo n.º 3
0
Arquivo: cli.py Projeto: zuodh/dagster
def execute_query(workspace,
                  query,
                  variables=None,
                  use_sync_executor=False,
                  instance=None):
    check.inst_param(workspace, 'workspace', Workspace)
    check.str_param(query, 'query')
    check.opt_dict_param(variables, 'variables')
    instance = (check.inst_param(instance, 'instance', DagsterInstance)
                if instance else DagsterInstance.get())
    check.bool_param(use_sync_executor, 'use_sync_executor')

    query = query.strip('\'" \n\t')

    locations = [
        RepositoryLocation.from_handle(x)
        for x in workspace.repository_location_handles
    ]

    context = DagsterGraphQLContext(
        locations=locations,
        instance=instance,
        version=__version__,
    )

    executor = SyncExecutor() if use_sync_executor else GeventExecutor()

    result = graphql(
        request_string=query,
        schema=create_schema(),
        context_value=context,
        variable_values=variables,
        executor=executor,
    )

    result_dict = result.to_dict()

    context.drain_outstanding_executions()

    # Here we detect if this is in fact an error response
    # If so, we iterate over the result_dict and the original result
    # which contains a GraphQLError. If that GraphQL error contains
    # an original_error property (which is the exception the resolver
    # has thrown, typically) we serialize the stack trace of that exception
    # in the 'stack_trace' property of each error to ease debugging

    if 'errors' in result_dict:
        check.invariant(len(result_dict['errors']) == len(result.errors))
        for python_error, error_dict in zip(result.errors,
                                            result_dict['errors']):
            if hasattr(python_error,
                       'original_error') and python_error.original_error:
                error_dict['stack_trace'] = get_stack_trace_array(
                    python_error.original_error)

    return result_dict
Exemplo n.º 4
0
Arquivo: cli.py Projeto: G9999/dagster
def execute_query(workspace,
                  query,
                  variables=None,
                  use_sync_executor=False,
                  instance=None):
    check.inst_param(workspace, "workspace", Workspace)
    check.str_param(query, "query")
    check.opt_dict_param(variables, "variables")
    instance = (check.inst_param(instance, "instance", DagsterInstance)
                if instance else DagsterInstance.get())
    check.bool_param(use_sync_executor, "use_sync_executor")

    query = query.strip("'\" \n\t")

    context = DagsterGraphQLContext(
        workspace=workspace,
        instance=instance,
        version=__version__,
    )

    executor = SyncExecutor() if use_sync_executor else GeventExecutor()

    result = graphql(
        request_string=query,
        schema=create_schema(),
        context_value=context,
        variable_values=variables,
        executor=executor,
    )

    result_dict = result.to_dict()

    # Here we detect if this is in fact an error response
    # If so, we iterate over the result_dict and the original result
    # which contains a GraphQLError. If that GraphQL error contains
    # an original_error property (which is the exception the resolver
    # has thrown, typically) we serialize the stack trace of that exception
    # in the 'stack_trace' property of each error to ease debugging

    if "errors" in result_dict:
        check.invariant(len(result_dict["errors"]) == len(result.errors))
        for python_error, error_dict in zip(result.errors,
                                            result_dict["errors"]):
            if hasattr(python_error,
                       "original_error") and python_error.original_error:
                error_dict["stack_trace"] = get_stack_trace_array(
                    python_error.original_error)

    return result_dict
Exemplo n.º 5
0
import graphene
from flask import request, Flask
from flask_graphql import GraphQLView
from graphql.execution.executors.gevent import GeventExecutor
from schema import Query
from loaders import PlayerLoader

FLASK_DEBUG = os.environ.get('FLASK_DEBUG', False)
APPLICATION_PORT = os.environ.get('FLASK_PORT', 8080)

# Create the Flask app
application = Flask(__name__)

# Load config values specified above
application.config.from_object(__name__)
# Only enable Flask debugging if an env var is set to true
application.debug = FLASK_DEBUG in ['true', 'True', '1']

schema = graphene.Schema(query=Query)
# https://github.com/graphql-python/flask-graphql
application.add_url_rule('/',
                         view_func=GraphQLView.as_view(
                             'graphql',
                             schema=schema,
                             graphiql=True,
                             context={'player_loader': PlayerLoader()},
                             executor=GeventExecutor()))

if __name__ == '__main__':
    application.run(host='0.0.0.0', port=APPLICATION_PORT)
Exemplo n.º 6
0
  def before_request():
    g.start = time.time()
  
  @app.teardown_request
  def teardown_request(exception=None):
    diff = time.time() - g.start
    print '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
    print 'EL REQUEST TOTAL TOMO =>', diff
    print '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
    
  CORS(app)
    
  return app

if __name__ == '__main__':
  app = create_app(executor=GeventExecutor(), graphiql=True)
  
  @app.errorhandler(Exception)
  def unhandled_exception(e):
    return make_response(jsonify({'error': str(e)}), 500)
  
#   @app.route('/api/v2/transfer', methods=['POST'])
#   def transfer():
#     try:
#       req = request.json

#       def build_amount( a ):
#         if not a: return None
#         return { "amount": int(Decimal(a)*ASSET_PRECISION), "asset_id" : ASSET_ID }
      
#       print req.get('from')