Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// something went bad when configuring the graphql server, we do not
// swallow the error and display it in the server-side logs
Logger.error(error, "[GraphQL Server] Something bad happened when handling a request on the GraphQL server");
// return the default graphql options anyway
return defaultGraphQLOptions;
}
})
);
// Start GraphiQL if enabled
if (config.graphiql) {
// GraphiQL endpoint
expressServer.use(
config.graphiqlPath,
graphiqlExpress({
// GraphiQL options
...config.graphiqlOptions,
// endpoint of the graphql server where to send requests
endpointURL: config.path
})
);
}
// bind the specified paths to the Express server running Apollo + GraphiQL
WebApp.connectHandlers.use(expressServer);
}
return newNotification;
},
},
Subscription: {
newNotification: {
subscribe: () => pubsub.asyncIterator(NOTIFICATION_SUBSCRIPTION_TOPIC)
}
},
};
const schema = makeExecutableSchema({ typeDefs, resolvers });
const app = express();
app.use('*', cors({ origin: `http://localhost:3000` }));
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema }));
app.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
subscriptionsEndpoint: `ws://localhost:4000/subscriptions`
}));
const ws = createServer(app);
ws.listen(4000, () => {
console.log('Go to http://localhost:4000/graphiql to run queries!');
new SubscriptionServer({
execute,
subscribe,
schema
}, {
server: ws,
path: '/subscriptions',
});
});
const PORT = 4000;
const graphQLServer = express();
console.log(process.env.CLIENT_URL);
const client = process.env.CLIENT_URL;
graphQLServer.use('*', cors({ origin: client }));
const myGraphQLSchema = makeExecutableSchema({
typeDefs: schema,
resolvers,
logger: console,
});
graphQLServer.use('/graphql', bodyParser.json(), graphqlExpress({ schema: myGraphQLSchema }));
graphQLServer.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
graphQLServer.listen(PORT, () =>
console.log(`GraphQL Server is now running on http://localhost:${PORT}`),
);
schema,
context: {
models,
user: req.user
}
}))
)
const subscriptionsEndpoint =
process.env.NODE_ENV === 'production'
? `wss://fake-youtube.herokuapp.com/subscriptions`
: `ws://localhost:${PORT}/subscriptions`
server.use(
'/graphiql',
graphiqlExpress({
endpointURL: '/graphql',
subscriptionsEndpoint
})
)
if (process.env.NODE_ENV === 'production') {
server.use(express.static('client/build'))
server.get('*', (req, res) => {
res.sendFile(path.resolve('client', 'build', 'index.html'))
})
}
const ws = createServer(server)
ws.listen(PORT, () => {
console.log(`APOLLO SERVER UP`)
new SubscriptionServer(
export default (
pss: PssAPI,
db: DB,
port: number,
app: express$Application,
) => {
const schema = createSchema(pss, db, port)
const log = debug('onyx:graphql')
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema }))
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }))
return {
schema,
onCreated: (server: net$Server) => {
SubscriptionServer.create(
{
execute,
schema,
subscribe,
},
{ path: '/graphql', server },
)
},
}
}
app.use(
config.GRAPHQL_ROUTE,
bodyParser.json(),
graphqlExpress((req: any) => {
return {
schema,
context: {
db: lowdb,
user: req.user
}
};
})
);
app.use(
config.GRAPHIQL_ROUTE,
graphiqlExpress({ endpointURL: config.GRAPHQL_ROUTE, subscriptionsEndpoint: config.WEBSOCKET_ENDPOINT })
);
}
app.use(cors(), auth);
app.use(
config.GRAPHQL_ROUTE,
bodyParser.json(),
graphqlExpress((req?: express.Request) => {
return {
schema,
context: {
user: (req as any).user
}
};
})
);
app.use(
config.GRAPHIQL_ROUTE,
graphiqlExpress({ endpointURL: config.GRAPHQL_ROUTE, subscriptionsEndpoint: config.WEBSOCKET_ENDPOINT })
);
}
server.set('port', port)
server.use(
cors(),
bodyParser.json(),
authMiddleware,
)
server.use('/mia/:type', miaEndpoints)
server.use("/image", upload.single("file") , imageRoute)
server.use('/graphiql', graphiqlExpress({
endpointURL: '/'
}))
server.use('/iiif/:identifier/info.json', info)
server.use('/iiif/:identifier/:region/:size/:rotation/:quality.:format', iiif)
server.use('/', graphqlExpress((req, res) => {
return {
schema,
context: req
}
}))