y react app always send post request to http://localhost:3000 and it's throw error like this :
createHttpLink.ts:121 POST http://localhost:3000/[object%20Object] 404 (Not Found)
It is happen when I try to pass my uri to HttpLink but it's working fine when I directly pass my uri to ApolloClient I have tried solutions from many sources but still not working for me please help How can I solve this problem
Here is my code.
Client side
const httpLink = new HttpLink({
uri: "http://localhost:4000/graphql",
credentials: "include"
});
const wsLink = new WebSocketLink({
uri: ws://localhost:4000/graphql,
options: {
reconnect: true
}
});
const splitLink = split(
({ query }) => {
const definition = getMainDefinition(query)
return (
definition.kind === 'OperationDefinition' &&
definition.operation === 'subscription'
)
},
wsLink,
httpLink
)
const client = new ApolloClient({
uri: splitLink,
cache: new InMemoryCache(),
export default function ApolloProvider(props){
return <Provider client={client }{...props}/>
}
Server Side
const SERVER_PORT = 4000;
const DB_URI = "xxxxxxxxxxxxxxx";
const app = express();
const pubsub = new PubSub();
app.use(cors())
const apolloServer = new ApolloServer({
typeDefs: gql${typeDefs},
resolvers,
context: ({ req }) => ({ req, pubsub })
});
const db = async () => {
try {
const success = await mongoose.connect(DB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
console.log('DB Connected');
} catch (error) {
console.log('DB Connection Error', error);
}
};
db();
apolloServer.applyMiddleware({ app });
const httpserver = http.createServer(app);
apolloServer.installSubscriptionHandlers(httpserver);
app.get('/', function (req, res) {
res.json({
data: 'BLANK PAGE !'
});
});
httpserver.listen({ port: SERVER_PORT }, () => {
console.log( Server ready at http://localhost:${SERVER_PORT} let's start!)
})