Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import playground from 'graphql-playground-middleware-lambda'
import { GITHUB_OAUTH_TOKEN, REACT_APP_GRAPHQL_ENDPOINT } from '../config/env'
const headers: { [key: string]: string } = {}
if (!REACT_APP_GRAPHQL_ENDPOINT) {
throw new Error(`You must define REACT_APP_GRAPHQL_ENDPOINT env in order to GraphQL Playground`)
}
// fulfil headers for Playground requests. Not strictly required, can be
// altered through the Playground Settings UI.
if (GITHUB_OAUTH_TOKEN) {
headers.authorization = `bearer ${GITHUB_OAUTH_TOKEN}`
}
const handle = playground({ endpoint: REACT_APP_GRAPHQL_ENDPOINT, headers })
/**
* Simple wrapper to avoid duplicated response (callback + return).
*/
const handler: Handler = (lambdaEvent, context, callback) => {
handle(lambdaEvent, context, callback)
}
export { handler }
if (output) {
output.headers['Access-Control-Allow-Origin'] = '*';
log.info(output.body);
} else {
log.error(error);
}
callback(error, output);
}
const handler = graphqlLambda({ schema: myGraphQLSchema, tracing: true });
return handler(event, context, callbackFilter);
};
// for local endpointURL is /graphql and for prod it is /stage/graphql
exports.playgroundHandler = lambdaPlayground({
endpoint: process.env.REACT_APP_GRAPHQL_ENDPOINT ? process.env.REACT_APP_GRAPHQL_ENDPOINT : '/production/graphql'
});
try {
JSON.parse(event.body);
} catch (err) {
const msg = 'Invalid JSON';
log(msg, err);
return callback(null, {
body: msg,
statusCode: 422
});
}
return handler(event, context, callbackFilter);
};
exports.apiHandler = lambdaPlayground({
endpoint: process.env.GRAPHQL_ENDPOINT_URL
? process.env.GRAPHQL_ENDPOINT_URL
: '/production/graphql'
});
}
const { statusCode, headers, result: body } = await server.inject({
method,
url,
payload,
headers: reqHeaders,
validate: false
})
delete headers[`content-encoding`]
delete headers[`transfer-encoding`]
response(null, { statusCode, headers, body })
}
exports.playground = lambdaPlayground({
endpoint: `/graphql`
})
import GraphQLPlayground from 'graphql-playground-middleware-lambda'
export const handler = GraphQLPlayground({ endpoint: '/' })