Comparing version 0.2.3-alpha.0 to 0.2.3
@@ -94,3 +94,3 @@ "use strict"; | ||
url: url, | ||
}, { req: req })]; | ||
}, { req: req, res: res })]; | ||
case 2: | ||
@@ -128,2 +128,3 @@ result = _b.sent(); | ||
req: req, | ||
res: res, | ||
})]; | ||
@@ -228,5 +229,5 @@ case 2: | ||
return useAsync(function (req, res) { return __awaiter(_this, void 0, void 0, function () { | ||
var variableValues, result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
var variableValues, C, _a, result; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
@@ -246,13 +247,21 @@ variableValues = info.variables.reduce(function (variables, variable) { | ||
}, {}); | ||
if (!sofa_1.isContextFn(sofa.context)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, sofa.context({ req: req, res: res })]; | ||
case 1: | ||
_a = _b.sent(); | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
_a = sofa.context; | ||
_b.label = 3; | ||
case 3: | ||
C = _a; | ||
return [4 /*yield*/, sofa.execute({ | ||
schema: sofa.schema, | ||
source: graphql_1.print(operation), | ||
contextValue: sofa_1.isContextFn(sofa.context) | ||
? sofa.context({ req: req }) | ||
: sofa.context, | ||
contextValue: C, | ||
variableValues: variableValues, | ||
operationName: info.operation.name && info.operation.name.value, | ||
})]; | ||
case 1: | ||
result = _a.sent(); | ||
case 4: | ||
result = _b.sent(); | ||
// TODO: add error handling for result.errors | ||
@@ -259,0 +268,0 @@ if (result.errors) { |
@@ -22,4 +22,5 @@ import { ExecutionResult } from 'graphql'; | ||
constructor(sofa: Sofa); | ||
start(event: StartSubscriptionEvent, { req, }: { | ||
start(event: StartSubscriptionEvent, { req, res, }: { | ||
req: any; | ||
res: any; | ||
}): Promise<ExecutionResult<any> | { | ||
@@ -29,4 +30,5 @@ id: string; | ||
stop(id: ID): Promise<StopSubscriptionResponse>; | ||
update(event: UpdateSubscriptionEvent, { req, }: { | ||
update(event: UpdateSubscriptionEvent, { req, res, }: { | ||
req: any; | ||
res: any; | ||
}): Promise<ExecutionResult<any> | { | ||
@@ -33,0 +35,0 @@ id: string; |
@@ -66,3 +66,3 @@ "use strict"; | ||
SubscriptionManager.prototype.start = function (event, _a) { | ||
var req = _a.req; | ||
var req = _a.req, res = _a.res; | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -88,2 +88,3 @@ var id, name, _b, document, operationName, variables, result; | ||
req: req, | ||
res: res, | ||
})]; | ||
@@ -118,3 +119,3 @@ case 1: | ||
SubscriptionManager.prototype.update = function (event, _a) { | ||
var req = _a.req; | ||
var req = _a.req, res = _a.res; | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -136,2 +137,3 @@ var variables, id, _b, subscription, url; | ||
req: req, | ||
res: res, | ||
})]; | ||
@@ -142,8 +144,8 @@ }); | ||
SubscriptionManager.prototype.execute = function (_a) { | ||
var id = _a.id, document = _a.document, name = _a.name, url = _a.url, operationName = _a.operationName, variables = _a.variables, req = _a.req; | ||
var id = _a.id, document = _a.document, name = _a.name, url = _a.url, operationName = _a.operationName, variables = _a.variables, req = _a.req, res = _a.res; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var variableNodes, variableValues, execution; | ||
var variableNodes, variableValues, C, _b, execution; | ||
var _this = this; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
@@ -163,2 +165,12 @@ variableNodes = this.operations.get(name).variables; | ||
}, {}); | ||
if (!sofa_1.isContextFn(this.sofa.context)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.sofa.context({ req: req, res: res })]; | ||
case 1: | ||
_b = _c.sent(); | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
_b = this.sofa.context; | ||
_c.label = 3; | ||
case 3: | ||
C = _b; | ||
return [4 /*yield*/, graphql_1.subscribe({ | ||
@@ -169,8 +181,6 @@ schema: this.sofa.schema, | ||
variableValues: variableValues, | ||
contextValue: sofa_1.isContextFn(this.sofa.context) | ||
? this.sofa.context({ req: req }) | ||
: this.sofa.context, | ||
contextValue: C, | ||
})]; | ||
case 1: | ||
execution = _b.sent(); | ||
case 4: | ||
execution = _c.sent(); | ||
if (iterall_1.isAsyncIterable(execution)) { | ||
@@ -177,0 +187,0 @@ // successful |
@@ -5,2 +5,3 @@ import { GraphQLArgs, ExecutionResult, DocumentNode } from 'graphql'; | ||
req: any; | ||
res: any; | ||
}) => ContextValue; | ||
@@ -7,0 +8,0 @@ export declare type Context = ContextValue | ContextFn; |
{ | ||
"name": "sofa-api", | ||
"description": "Create REST APIs with GraphQL", | ||
"version": "0.2.3-alpha.0", | ||
"version": "0.2.3", | ||
"main": "dist/index.js", | ||
@@ -6,0 +6,0 @@ "typings": "dist/index.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
157521
50
1740