You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import { ApolloServer } from '@apollo/server';
import { ApolloGateway } from '@apollo/gateway';
import { expressMiddleware } from '@apollo/server/express4';
import { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer';
import { ApolloServerPluginSubscriptionCallback } from '@apollo/server/plugin/subscriptionCallback';
import express from 'express';
import http from 'http';
import { WebSocketServer } from 'ws';
import { useServer } from 'graphql-ws/lib/use/ws';
import cors from 'cors';
import * as dotenv from 'dotenv';
async function startServer() {
const app = express();
const httpServer = http.createServer(app);
const gateway = new ApolloGateway({
uplinkMaxRetries: 3,
fallbackPollIntervalInMs: 60000
});
const wsServer = new WebSocketServer({
server: httpServer,
path: '/graphql',
});
// THIS gateway.schema is empty?
const serverCleanup = useServer(
{
schema: gateway.schema
},
wsServer
);
const server = new ApolloServer({
gateway,
plugins: [
ApolloServerPluginSubscriptionCallback(),
ApolloServerPluginDrainHttpServer({ httpServer }),
{
async serverWillStart() {
return {
async drainServer() {
await serverCleanup.dispose();
},
};
},
},
],
});
await server.start();
app.use(
'/graphql',
cors<cors.CorsRequest>(),
express.json(),
expressMiddleware(server, {
context: async ({ req }) => ({
token: req.headers.token
}),
}),
);
const PORT = process.env.PORT || 4700;
httpServer.listen(PORT, () => {
console.log(`🚀 Query endpoint ready at http://localhost:${PORT}/graphql`);
console.log(`🚀 Subscription endpoint ready at ws://localhost:${PORT}/graphql`);
});
// Requests to `http://localhost:4700/health` now return "Okay!"
app.get('/health', (req, res) => {
res.status(200).send('Okay!');
});
}
startServer().catch((error) => {
console.error('Failed to start the server:', error);
process.exit(1);
});
The server starts up but when I try to execute I get this error:
Internal error occurred during message handling. Please check your implementation. Error: The GraphQL schema is not provided
So is there a way to get the schema from Apollo Studio (Managed Environment)
so that when I hook up the websockets it knows what the graphql schema is?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi There
I have the following setup:
The server starts up but when I try to execute I get this error:
Internal error occurred during message handling. Please check your implementation. Error: The GraphQL schema is not provided
So is there a way to get the schema from Apollo Studio (Managed Environment)
so that when I hook up the websockets it knows what the graphql schema is?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions