Tag: Middleware
-
Cannot read properties of undefined (reading ‘isAuth’) in React and GraphQL application
0 I’m encountering an error when trying to create a post in my React application using a GraphQL mutation. The error message is: { "errors": [ { "message": "Cannot read properties of undefined (reading ‘isAuth’)", "status": 500 } ], "data": { "createPost": null } } This suggests that the req.isAuth property is undefined when the…
-
How Can I Pass the Auth Middleware to the Apollo GraphQL Server
1 My App.js const mongoose = require(‘mongoose’); const dotenv = require(‘dotenv’); const { ApolloServer } = require(‘apollo-server’); const { startStandaloneServer } = require(‘@apollo/server/standalone’); const typeDefs = require(‘./apolloGraphql/schema’); const resolvers = require(‘./apolloGraphql/resolvers’); const auth = require(‘./Middleware/Auth’); dotenv.config({ path: ‘./config/.env’ }); const server = new ApolloServer({ typeDefs, resolvers, }); mongoose .connect(process.env.MONGOURI) .then((result) => { return server.listen(process.env.PORT, (req,…
-
Passing request parameter into middleware which uses ‘createHandler’ function of ‘graphql-http’
0 I have created an express server which uses GraphQL for handling requests over HTTP. Among others, the express server has the two middlewares below. app.use(authenticate); app.use(‘/graphql’, createHandler({ schema })); The authenticate middleware invokes a function which has req, res and next as parameters and in certain conditions assigns a value to req.user. How can…
-
Passing request parameter into middleware using createHandler function of graphql-http
0 I have created an express server which uses GraphQL for handling requests over HTTP. Among others, the express server has the two middlewares below. app.use(authenticate); app.use(‘/graphql’, createHandler({ schema })); The authenticate middleware invokes a function which has req, res and next as parameters and in certain conditions assigns a value to req.user. How can…
-
How can I add a variable to all requests in apollo client?
1 I need a middleware so I can pass a variable in all my requests. This is what I have, but isn’t working. const httpLink = new HttpLink({ uri: process.env.REACT_APP_BASE_URL_API }); const addVariableMiddleware = new ApolloLink((operation, forward) => { operation.variables.newVariable = "nuevavariable"; return forward(operation); }); const client = new ApolloClient({ cache: new InMemoryCache(), link: from([addVariableMiddleware,…