UNPKG

jok

Version:

Bundle of utility functions for code generation related to nodejs and graphql

30 lines (29 loc) 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var rootType_1 = require("../../utils/rootType"); function default_1(_a) { var _b; var rootType = _a.rootType, hasVariables = _a.hasVariables, queryName = _a.queryName, returnType = _a.returnType, _c = _a.isWatchQuery, isWatchQuery = _c === void 0 ? false : _c; var methodName = (_b = {}, _b[rootType_1.RootType.Query] = 'query', _b[rootType_1.RootType.Mutation] = 'mutate', _b[rootType_1.RootType.Subscription] = 'subscribe', _b)[rootType]; if (isWatchQuery && rootType === rootType_1.RootType.Query) { methodName = 'watchQuery'; } if (rootType === rootType_1.RootType.Subscription) { return "\n\t\t// apollo call\n\t\tconst zenObs = this.client." + methodName + "<" + returnType + ">({\n\t\t\t...mergedOptions,\n\t\t\tquery: " + rootType + "," + (hasVariables ? "\n\t\t\tvariables: props," : '') + "\n\t\t})\n\n\t\treturn from(fixObservable(zenObs)).pipe(\n\t\t\tmap(result => getResultData<" + returnType + ">(result, '" + queryName + "'))\n\t\t)"; } if (isWatchQuery) { return "\n\t\tconst zenObs = this.client.watchQuery<" + returnType + ">({\n\t\t\t...mergedOptions,\n\t\t\tquery," + (hasVariables ? "\n\t\t\tvariables: props," : '') + "\n\t\t})\n\n\t\tconst { subscribeToMore = [] } = mergedOptions\n\n\t\tsubscribeToMore.forEach((x: any) => {\n\t\t zenObs.subscribeToMore({\n\t\t\t...(typeof x.graphqlDocument === 'function'\n\t\t\t\t\t\t? x.graphqlDocument(this.subscriptionDocument)\n\t\t\t\t\t\t: x.graphqlDocument),\n\t\t\tupdateQuery: x.updateQuery,\n\t\t })\n\t\t})\n\n\t\treturn from(fixObservable(zenObs)).pipe(\n\t\t\tmap(result => getResultData<" + returnType + ">(result, '" + queryName + "'))\n\t\t)"; } return "\n\t\t// apollo call\n\t\treturn this.client." + methodName + "({\n\t\t\t...mergedOptions,\n\t\t\t" + rootType + "," + (hasVariables ? "\n\t\t\tvariables: props," : '') + "\n\t\t}).then(result => getResultData<" + returnType + ">(result, '" + queryName + "'))"; } exports.default = default_1;