diff --git a/CockpitSpace/GraphQLRestartSimulation.js b/CockpitSpace/GraphQLRestartSimulation.js new file mode 100644 index 000000000..e066a5cbb --- /dev/null +++ b/CockpitSpace/GraphQLRestartSimulation.js @@ -0,0 +1,64 @@ + +const GRAPHQL_MUTATION_RESTART_SIMULATION = Apollo.gql` + mutation operations_RunSimulation( + $simulation: operations_SimulationInput) + { + operations_RunSimulation(simulation: $simulation) + } + ` + +async function restartSimulation (simulationParams) { + try { + const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY) + + if (accessToken === null) { + if (ERROR_LOG === true) { logger.write('[ERROR] restartSimulation -> Can not restart the simulation because the user is not logged in. ') } + return + } + + const apolloClient = new Apollo.lib.ApolloClient({ + networkInterface: Apollo.lib.createNetworkInterface({ + uri: window.canvasApp.graphQL.masterAppApiUrl, + transportBatching: true + }), + connectToDevTools: true + }) + + const networkInterface = Apollo.lib.createNetworkInterface({ + uri: window.canvasApp.graphQL.masterAppApiUrl + }) + + networkInterface.use([{ + applyMiddleware (req, next) { + req.options.headers = { + authorization: `Bearer ${accessToken}` + } + next() + } + }]) + + const graphQlRestartSimuulation = () => { + return new Promise((resolve, reject) => { + apolloClient.mutate({ + mutation: GRAPHQL_MUTATION_RESTART_SIMULATION, + variables: { + simulation: simulationParams + } + }) + .then(response => { + resolve(true) + }) + .catch(err => { + if (ERROR_LOG === true) { logger.write('[ERROR] restartSimulation -> ApolloClient error restarting simulation -> err = ' + err.stack) } + reject(err) + }) + }) + } + + let result = await graphQlRestartSimuulation() + + return result + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] restartSimulation -> err = ' + err.stack) } + } +} diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js index a5c4c3286..efb0350ed 100644 --- a/CockpitSpace/RestartSimulation.js +++ b/CockpitSpace/RestartSimulation.js @@ -71,7 +71,15 @@ function newRestartSimulation () { } async function onMouseClick (event) { + let simulationParams = { + beginDatetime: 1554087600, + resumeExecution: true, + timePeriodDailyArray: ['05-min', '10-min'], + timePeriodMarketArray: ['01-hs', '02-hs'] + } + let result = await restartSimulation(simulationParams) + console.log('GRAPH QL EXECUTION ' + result) } function physics () { @@ -129,4 +137,3 @@ function newRestartSimulation () { browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) } } - diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index dd9e8b5b5..d533d8c14 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -91,7 +91,7 @@ function newWorkspace () { resolve(true) }) .catch(err => { - if (ERROR_LOG === true) { logger.write('[ERROR] saveToStrategyzer -> ApolloClient error getting user strategies -> err = ' + err.stack) } + if (ERROR_LOG === true) { logger.write('[ERROR] saveToStrategyzer -> ApolloClient error updating user strategies -> err = ' + err.stack) } reject(err) }) })