Last active
June 26, 2019 13:30
-
-
Save hmelenok/d019105553d26e1c57e185aedbdb73cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {Api} from '@shelf/sdk'; | |
| import {Meteor} from 'meteor/meteor'; | |
| const graphqlConfig = { | |
| apiKey: Meteor.settings.public.decisionTree.apiKey, | |
| apiUrl: `https://${Meteor.settings.public.decisionTree.graphqlAPIHost}/graphql` | |
| }; | |
| // Todo: Setup Apollo during Visual Editing implementation and switch to QueryLayer | |
| class DecisionTreeApi extends Api { | |
| static getStep(stepId, gemId) { | |
| const body = { | |
| query: ` | |
| query ($gemId: ID!, $stepId: ID!) { | |
| step(gemId: $gemId, stepId: $stepId) { | |
| id | |
| title | |
| text | |
| question { | |
| id | |
| title | |
| description | |
| answers { | |
| id | |
| title | |
| nextStep { | |
| id | |
| } | |
| } | |
| } | |
| } | |
| } | |
| `, | |
| variables: { | |
| stepId, | |
| gemId | |
| } | |
| }; | |
| return this.post(graphqlConfig.apiUrl, body, { | |
| 'x-api-key': graphqlConfig.apiKey | |
| }); | |
| } | |
| static async getTreeSteps(gemId) { | |
| const body = { | |
| query: ` | |
| query($gemId: ID!) { | |
| tree(gemId: $gemId) { | |
| id | |
| title | |
| text | |
| question { | |
| title | |
| description | |
| answers { | |
| title | |
| id | |
| nextStep { | |
| id | |
| } | |
| } | |
| } | |
| } | |
| } | |
| `, | |
| variables: { | |
| gemId | |
| } | |
| }; | |
| const {data} = await this.post(graphqlConfig.apiUrl, body, { | |
| 'x-api-key': graphqlConfig.apiKey | |
| }); | |
| return data.tree || []; | |
| } | |
| static async saveStepTextDraft({gemId, stepId, text}) { | |
| const body = { | |
| query: ` | |
| mutation ($gemId: ID!, $stepId: ID!, $text: String!) { | |
| saveStepTextDraft(gemId: $gemId, stepId: $stepId, text: $text) | |
| } | |
| `, | |
| variables: { | |
| gemId, | |
| stepId, | |
| text | |
| } | |
| }; | |
| return this.post(graphqlConfig.apiUrl, body, { | |
| 'x-api-key': graphqlConfig.apiKey | |
| }); | |
| } | |
| static async upsertWholeTree({gemId, steps}) { | |
| const body = { | |
| query: ` | |
| mutation ($gemId: ID!, $steps: AWSJSON!) { | |
| upsertTree(gemId: $gemId, steps: $steps) { | |
| id | |
| title | |
| question { | |
| id | |
| title | |
| description | |
| answers { | |
| id | |
| title | |
| nextStep { | |
| id | |
| } | |
| } | |
| } | |
| } | |
| } | |
| `, | |
| variables: { | |
| gemId, | |
| steps | |
| } | |
| }; | |
| return this.post(graphqlConfig.apiUrl, body, { | |
| 'x-api-key': graphqlConfig.apiKey | |
| }); | |
| } | |
| } | |
| export default DecisionTreeApi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment