Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default (app, { schema, context }) => {
const openApi = OpenAPI({
schema,
info: {
title: "SpaceX REST API"
}
});
const basePath = "/rest";
app.use(cors());
app.use(
basePath,
sofa({
schema,
context,
onRoute(info) {
openApi.addRoute(info, { basePath });
}
})
);
// writes every recorder route
openApi.save("./swagger.json");
// expose rest docs
app.use(basePath, swaggerUi.serve, swaggerUi.setup(swaggerDocument));
};
async function start() {
const app = express()
app.use(cors())
app.get("/health", (req, res) => res.sendStatus(200))
const schema = makeExecutableSchema({
typeDefs,
resolvers,
resolverValidationOptions: {
requireResolversForResolveType: false
}
});
app.use("/rest", useSofa({
schema,
}))
// connect to db
const client = await connect(config.db);
const apolloConfig = {
schema,
context: async ({
req
}: { req: express.Request }) => {
// pass request + db ref into context for each resolver
return {
req: req,
db: client,
pubsub
pubSub.subscribe('REBUILD_EXTERNAL', async payload => {
if (external) {
log('schemas have changed', payload.name);
}
external = await createExternal(connection);
externalServer.schema = external.schema;
externalServer.context = external.context;
externalServer.schemaDerivedData = externalServer.generateSchemaDerivedData(
externalServer.schema
);
if (config.sofaApi) {
app.use(
`${config.path}api`,
sofa({
schema: external.schema,
ignore: ['Prime_Document'],
})
);
}
});
export default (app, { schema, context }) => {
const openApi = OpenAPI({
schema,
info: {
title: "SpaceX REST API"
}
});
const basePath = "/rest";
app.use(cors());
app.use(
basePath,
sofa({
schema,
context,
onRoute(info) {