Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import schema from './schema/schema';
import { authenticatedMiddleware } from './auth';
import { dataloadersMiddleware } from './loaders/dataloadersMiddleware';
const app = new Koa();
const router = new Router();
app.context.pubnub = pubNubSetup();
// app.use(morgan('tiny'))
app.use(dataloadersMiddleware)
app.use(authenticatedMiddleware)
router.get('/', ctx => ctx.body = 'Hello World')
router.all('/playground', koaPlayground({
endpoint: '/graphql',
subscriptionEndpoint: `ws://localhost:${SERVER_PORT}/subscriptions`,
}))
router.all('/graphql', graphqlHTTP({
schema,
graphiql: true
}))
app.use(cors());
app.use(router.routes()).use(router.allowedMethods());
export default app;
tracing: true,
}),
);
// Optionally add the playground
if (
this.playgroundOptions.enabled &&
typeof this.endpoints.playground === "string"
) {
const playgroundOptions: playgroundOptions = {
...this.playgroundOptions,
endpoint: this.endpoints.graphQL,
};
this.router.get(
this.endpoints.playground,
KoaPlaygroundMiddleware(playgroundOptions),
);
}
}
message: error.message,
locations: error.locations,
stack: error.stack,
};
},
};
};
const graphqlServer = graphqlHttp(graphqlSettingsPerReq);
// graphql batch query route
router.all('/graphql/batch', bodyParser(), graphqlBatchHttpWrapper(graphqlServer));
router.all('/graphql', graphqlServer);
router.all(
'/graphiql',
koaPlayground({
endpoint: '/graphql',
subscriptionEndpoint: '/subscriptions',
}),
);
app.use(logger());
app.use(cors());
app.use(router.routes()).use(router.allowedMethods());
export default app;
? config.processSchema(createSchema(strategies))
: createSchema(strategies),
override: (ctx: any) => {
const contextValue: Context = ctx[x];
return {
contextValue
};
}
})
);
// GraphiQL
// ========
// This is a graphical (get it, graph-i-QL) interface to the AuthX API.
this.all("/graphiql", createPlaygroundMiddleware({ endpoint: "/graphql" }));
// OAuth
// =====
// The core AuthX library supports the following OAuth2 grant types:
//
// - `authorization_code`
// - `refresh_token`
//
// Because it involves presentation elements, the core AuthX library does
// **not** implement the `code` grant type. Instead, a compatible reference
// implementation of this flow is provided by the `authx-interface` NPM
// package.
this.post(
"/",
contextMiddleware as AuthXMiddleware,
// router.get('/admin', async ctx => {
// await handle(ctx.req, ctx.res);
// ctx.respond = false;
// });
router.get('/signin', async ctx => {
await handle(ctx.req, ctx.res);
ctx.respond = false;
});
router.all('/graphql', graphqlServer);
if (process.env.NODE_ENV !== 'production') {
router.all(
'/playground',
koaPlayground({
endpoint: '/graphql'
})
);
}
router.get('*', async ctx => {
await handle(ctx.req, ctx.res);
ctx.respond = false;
});
server.use(async (ctx, next) => {
ctx.res.statusCode = 200;
await next();
});
server.use(cors());
message: error.message,
locations: error.locations,
stack: error.stack,
};
},
};
};
const graphqlServer = graphqlHttp(graphqlSettingsPerReq);
// graphql batch query route
router.all('/graphql/batch', bodyParser(), graphqlBatchHttpWrapper(graphqlServer));
router.all('/graphql', graphqlServer);
router.all(
'/graphiql',
koaPlayground({
endpoint: '/graphql',
subscriptionEndpoint: `ws://localhost:${process.env.GRAPHQL_PORT}/subscriptions`,
}),
);
app.use(logger());
app.use(cors());
app.use(router.routes()).use(router.allowedMethods());
export default app;
}));
}
// GraphiQL?
if (process.env.GRAPHIQL) {
router.get(
`/${paths.GRAPHIQL_PATH}`,
graphiqlKoa({ endpointURL: GRAPHQL_ENDPOINT }),
);
}
// GraphQL Playground?
if (process.env.PLAYGROUND) {
router.all(
`/${paths.PLAYGROUND_PATH}`,
koaPlayground({ endpoint: GRAPHQL_ENDPOINT }),
);
}
// Koa Heartbeat
app.use(koaHeartbeat({ path: `/${paths.LIVENESS_PATH}`, body: 'ok' }));
app.use(router.routes());
app.use(router.allowedMethods());
export default app;
res,
dataloaders,
user,
pubSub
}
}
return options
}
const graphqlServer = graphqlHttp(graphqlSettingsPerReq)
router.all('/graphql', bodyParser(), graphqlServer)
if (process.env.NODE_ENV !== 'production') {
router.all(
'/graphiql',
koaPlayground({
endpoint: '/graphql',
subscriptionEndpoint: '/subscriptions'
})
)
}
app.use(logger())
app.use(cors())
app.use(router.routes()).use(router.allowedMethods())
export default app
]).then(([headers, endpoint]) => {
const app = new Koa();
app.use(koaPlayground({
endpoint,
settings: {
'editor.cursorShape': 'line',
'editor.reuseHeaders': true,
},
tabs: [{
endpoint,
headers,
}],
}));
const port = options.port || 3000;
app.listen(port);
const graphiqlUrl = `http://localhost:${port}`;
return graphiqlUrl;