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 express from 'express';
import graphQLHTTP from 'express-graphql';
import graphql from 'graphql';
import schema from './schema.js';
import mongo from './mongo';
const isDevelopment = process.env.NODE_ENV !== "production";
const db = 'humble';
const path = "mongodb://localhost:27017/"+db;
const app = express();
let PORT = 8000;
app.use('/', graphQLHTTP({
schema,
graphiql:true,
}))
let server = app.listen(PORT, function () {
console.log(`GraphQL server listening at ${PORT}`);
console.log(`GraphIQL available at http://localhost:${PORT}/graphiql`);
mongo.init(path);
});
I can confirm that graphql is working correctly and that my queries and mutations are correct via graphiql.
For Apollo I copied the lib folder from the with-apollo example. Here is the networkInterface argument to ApolloClient in the initClient.js file:
networkInterface: createNetworkInterface({
// uri: 'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn',
uri:'http://localhost:8000',
opts: {
credentials: 'same-origin'
// Pass headers here if your graphql server requires them
}
})
The problem: I'm able query fine, but when I try to insert an item via a mutation I get:
[Error] Failed to load resource: Preflight response is not successful (localhost, line 0)
[Error] Fetch API cannot load http://localhost:8000/. Preflight response is not successful
My research points to a CORS issue, but I have "credentials: 'same-origin'" in my initialization, and I don't get any errors querying data, so I'm not sure how to proceed. Any ideas?
The text was updated successfully, but these errors were encountered:
Thank you. I'm beginning to think this is a GraphQL / Express issue not a Next issue.
I added the cors package to my project, imported it, and added app.use(cors()) just above app.use('/', graphQLHTTP({
I'm now getting
Failed to load resource: the server responded with a status of 400 (Bad Request)
I'm running graphql and next as separate processes, but from the same project folder. My package.json contains the following scripts:
Here is my graphql.js file:
I can confirm that graphql is working correctly and that my queries and mutations are correct via graphiql.
For Apollo I copied the lib folder from the with-apollo example. Here is the networkInterface argument to ApolloClient in the initClient.js file:
The problem: I'm able query fine, but when I try to insert an item via a mutation I get:
Here's the code for my AddPost button:
My research points to a CORS issue, but I have "credentials: 'same-origin'" in my initialization, and I don't get any errors querying data, so I'm not sure how to proceed. Any ideas?
The text was updated successfully, but these errors were encountered: