6 examples of 'apollo server applymiddleware' in JavaScript

Every line of 'apollo server applymiddleware' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
7export default function applyMiddleware(...middleware: LegacyMiddleware[]) {
8 var next: LegacyDispatchFunction = finalDispatch;
9 for (var i = middleware.length - 1; i >= 0; i--) {
10 next = applyMiddlewareInternal(middleware[i], next);
11 }
12
13 getGlobalContext().legacyDispatchWithMiddleware = next;
14}
89public async mount(app: Koa) {
90 this.apolloServer.applyMiddleware({app});
91}
91applyMiddleware(...middlewares: interfaces.Middleware[]): void {
92 this.container.applyMiddleware(...middlewares)
93}
4module.exports = function applyMiddleware () {
5 var middlewares = [].slice.call(arguments)
6
7 return function (createStore) {
8 return function (reducer, initialState, enhancer) {
9 var store = createStore(reducer, initialState, enhancer)
10 var chain = []
11
12 var middlewareAPI = {
13 getState: store.getState,
14 dispatch: function (action) {
15 return dispatch(action)
16 }
17 }
18
19 chain = middlewares.map(function (middleware) {
20 return middleware(middlewareAPI)
21 })
22
23 var dispatch = compose.apply(null, chain)(store.dispatch)
24
25 return extend(store, {
26 dispatch: dispatch
27 })
28 }
29 }
30}
9export function createApolloServer(config: {
10 schemaDir: string;
11 endpointMap: { [key: string]: string };
12 mocks: boolean | IMocks;
13}) {
14 const { schemaDir, endpointMap, mocks } = config;
15 const typesArray = fileLoader(schemaDir, { recursive: true });
16 const typeDefs = mergeTypes(typesArray, { all: true });
17 const schema: GraphQLSchema = makeExecutableSchema({
18 typeDefs,
19 schemaDirectives: {
20 rest: RestDirective
21 },
22 });
23
24 if (mocks) {
25 addMockFunctionsToSchema({
26 schema,
27 mocks: typeof mocks === 'boolean' ? {} : mocks,
28 preserveResolvers: true,
29 });
30 }
31
32 return new ApolloServer({
33 schema,
34 context: () => ({
35 endpointMap,
36 // TODO: permission verification will be added
37 restLoader: createRestLoader(),
38 }),
39 resolvers: {
40 Date: dateScalarType,
41 },
42 });
43};
4export async function startServer(config) {
5 const app = await createServer({
6 host: config.host,
7 port: config.port,
8 });
9
10 await apolloServer.applyMiddleware({
11 app,
12 path: config.path,
13 });
14
15 await apolloServer.installSubscriptionHandlers(app.listener);
16
17 return mountServer("GraphQL", app);
18}

Related snippets