Skip to content
Permalink
Browse files

enable context.request in mapping templates

  • Loading branch information...
JimmyHurrah committed Mar 5, 2019
1 parent 01c161e commit acad4497600e071eae56765a2dcfa671315c66a5
@@ -47,12 +47,14 @@ class AppSyncError extends Error {
const buildVTLContext = ({ root, vars, context, info }, result = null) => {
const {
jwt: { iss: issuer, sub },
request,
} = context;
const util = createUtils();
const args = javaify(vars);
const vtlContext = {
arguments: args,
args,
request,
identity: javaify({
sub,
issuer,
@@ -144,12 +144,12 @@ class SubscriptionServer {
}
}

async register({ documentAST, variables, jwt }) {
const clientId = jwt.sub;
async register({ documentAST, variables, context }) {
const clientId = context.jwt.sub;

const topicId = uuid();
log.info('register', { clientId, topicId });

const context = { jwt };
const registration = {
context,
documentAST,
@@ -228,11 +228,10 @@ class SubscriptionServer {
const executeGQL = async ({
schema,
documentAST,
jwt,
context,
variables,
operationName,
}) => {
const context = { jwt };
const output = await execute(
schema,
documentAST,
@@ -278,22 +277,23 @@ const createGQLHandler = ({ schema, subServer }) => async (req, res) => {
definitions: [{ operation: queryType }],
} = documentAST;

const context = { jwt, request: req };
switch (queryType) {
case 'query':
case 'mutation':
return res.send(
await executeGQL({
schema,
documentAST,
jwt,
context,
variables,
operationName,
}),
);
case 'subscription':
return res.send(
await subServer.register({
jwt,
context,
documentAST,
variables,
}),

0 comments on commit acad449

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.