Tag: express
-
Can’t consume context in my mutation resolver, request object passed instead Apollo Server v4
0 I am trying to pass the pubsub to resolvers. I am able to pass pubsub to subscription ‘subscribe’ functions via the useServer function, and as far as I can tell from research the expressMiddleware context should be passed to all resolvers, but when logging it out I’m just getting the request object. index.ts const…
-
CORS blocks mutation in GraphQL Yoga
6 I am working here with a graphql prisma backend and a graphql yoga express server on top of that. In the frontend, I am trying to call a signout mutation but its blocked by the CORS policy. Though I have added cors settings in my graphql yoga server, I keep getting this error. GraphQL…
-
apollo-server-express CORS issue
25 So I am migrating to apollo-server-express 2.3.3 ( I was using 1.3.6 ) I’ve followed several guides, making the necessary tweaks but am stuck in a CORS issue. According to the docs you have to use the applyMiddleware function to wire up the apollo server with express. I am currently doing the following: const…
-
Protect GraphQl queries and mutations with middleware
0 I’m developing an express app and experimenting with graphql. I’ve started to not using old endpoints I made before. The problem is some of my old endpoints protected by middlewares like: router.get( "/", [auth.verifyToken, auth.checkRole(["role1", "role2"])], someController.getAllThings ); So my question is how to protect queries and mutations with middlewares? node.js express graphql Share…
-
http-proxy-middleware and graphql
0 I have a simple graphql-server: const typeDefs = gql` type Message { id: ID! text: String! } type Query { getMessage: Message } `; const resolvers = { Query: { getMessage: () => { return { id: ‘1’, text: ‘Hello, World!’ }; } } }; async function startServer() { const server = new ApolloServer({…
-
How to define type for object in graphql schema?
-2 I have todo’s mongo schema like this: const todoSchema = new Schema( { userId: { type: String, required: true }, title: { type: String, required: true }, due_date: { date: { type: Number }, month: { type: Number }, year: { type: Number }, hours: { type: Number }, minute: { type: Number },…
-
How to import gql to create typedefs in apollo server v4?
0 In the version 3 of apollo server, we could use import {gql} from "apollo-server-express" to create typedefs and schemas. But in v4 of apollo server, apollo-server-express and apollo-server-core are depreciated and will be removed. So, instead of importing gql from apollo-server-express, how can we import gql I tried import gql from new @apollo/server and…
-
query mongodb with express and graphql
3 how do we use graph ql with mongo db here is my code with resolvers var resolvers = { test:()=>{ return getproducts() }, } const getproducts=()=>{ return new Promise((resolve,reject)=>{ Product.find({}).exec() .then(resp=>{ console.log("response is ",resp); let stringData = resp.toString() resolve(stringData); }).catch(err=>{ console.log(‘error is ‘,err); reject(err); }) }) } and schema is : test:String! i am…
-
FetchError: invalid json response body GraphQL
0 I’m using @apollo/datasource-rest to wrap a 3rd party API. The endpoint I’m trying to hit checks if an email is already in use or not. If the email is in use the response looks like this "body": "True", "statusCode": 200, "contentType": "application/json", If the email is not in use the api returns a 404…
-
How to properly pass a user and run middleware on apollo server v4
1 I am creating an apollo server v4 gql gateway with the express.js integration. I have user typedefs and user resolvers working and creating a jwt when a user is created. I then try to use my jwtMiddleware middleware on the /graphql endpoint so that it can validate a bearer token is being passed in…