Beispiel #1
0
 return __generator(this, function (_c) {
     switch (_c.label) {
         case 0:
             info = options.info, _a = options.args, args = _a === void 0 ? {} : _a;
             rawDocument = createDocument(options.fieldName, options.operation, info.fieldNodes, Object.keys(info.fragments).map(function (fragmentName) { return info.fragments[fragmentName]; }), info.operation.variableDefinitions);
             rawRequest = {
                 document: rawDocument,
                 variables: info.variableValues,
             };
             transforms = (options.transforms || []).concat([
                 new AddArgumentsAsVariables_1.default(options.schema, args),
                 new FilterToSchema_1.default(options.schema),
                 new AddTypenameToAbstract_1.default(options.schema),
                 new CheckResultAndHandleErrors_1.default(info, options.fieldName),
             ]);
             processedRequest = transforms_1.applyRequestTransforms(rawRequest, transforms);
             errors = graphql_1.validate(options.schema, processedRequest.document);
             if (errors.length > 0) {
                 throw errors;
             }
             if (!(options.operation === 'query' || options.operation === 'mutation')) return [3 /*break*/, 2];
             _b = transforms_1.applyResultTransforms;
             return [4 /*yield*/, graphql_1.execute(options.schema, processedRequest.document, info.rootValue, options.context, processedRequest.variables)];
         case 1: return [2 /*return*/, _b.apply(void 0, [_c.sent(),
                 transforms])];
         case 2:
             if (options.operation === 'subscription') {
                 // apply result processing ???
                 return [2 /*return*/, graphql_1.subscribe(options.schema, processedRequest.document, info.rootValue, options.context, processedRequest.variables)];
             }
             return [2 /*return*/];
     }
 });
Beispiel #2
0
 ? () => {
     return subscribe(
       runtimeSchema,
       document,
       rootValue,
       contextValue,
       variableValues,
       operationName,
       fieldResolver,
       subscriptionFieldResolver,
     );
   }
 return __generator(this, function (_b) {
     switch (_b.label) {
         case 0:
             if (operation === 'mutation') {
                 type = schema.getMutationType();
             }
             else if (operation === 'subscription') {
                 type = schema.getSubscriptionType();
             }
             else {
                 type = schema.getQueryType();
             }
             if (!type) return [3 /*break*/, 3];
             graphqlDoc = createDocument(schema, fragmentReplacements, type, fieldName, operation, info.fieldNodes, info.fragments, info.operation.variableDefinitions);
             errors = graphql_1.validate(schema, graphqlDoc);
             if (errors.length > 0) {
                 throw errors;
             }
             operationDefinition = graphqlDoc.definitions.find(function (_a) {
                 var kind = _a.kind;
                 return kind === graphql_1.Kind.OPERATION_DEFINITION;
             });
             variableValues = {};
             if (operationDefinition &&
                 operationDefinition.kind === graphql_1.Kind.OPERATION_DEFINITION &&
                 operationDefinition.variableDefinitions &&
                 Array.isArray(operationDefinition.variableDefinitions)) {
                 for (_i = 0, _a = operationDefinition.variableDefinitions; _i < _a.length; _i++) {
                     definition = _a[_i];
                     key = definition.variable.name.value;
                     actualKey = key.startsWith('_') ? key.slice(1) : key;
                     variableValues[key] = args[actualKey] != null ? args[actualKey] : info.variableValues[key];
                 }
             }
             if (!(operation === 'query' || operation === 'mutation')) return [3 /*break*/, 2];
             return [4 /*yield*/, graphql_1.execute(schema, graphqlDoc, info.rootValue, context, variableValues)];
         case 1:
             result = _b.sent();
             return [2 /*return*/, errors_1.checkResultAndHandleErrors(result, info, fieldName)];
         case 2:
             if (operation === 'subscription') {
                 return [2 /*return*/, graphql_1.subscribe(schema, graphqlDoc, info.rootValue, context, variableValues)];
             }
             _b.label = 3;
         case 3: throw new Error('Could not forward to merged schema');
     }
 });