How does one add GraphQL to the server?
theednaffattack opened this issue · comments
I've tried adding graphiqlExpress to the server instance with no luck at all (code below). This usually gets the job done. Where have I gone wrong? Do I need to do something with the routes file?
const buildOptions = async (req, res) => {
const mongo = await connectMongo();
console.log("trying auth");
const query = req.query.query || req.body.query;
if (query && query.length > 2000) {
throw new Error("Query too large.");
}
return {
context: {
dataloaders: buildDataLoaders(mongo),
mongo
}, // this context object is passed to all resolvers.
formatError,
schema
};
};
server.use(
"/graphql",
bodyParser.json(),
passport.authenticate("jwt", {
session: false
}),
graphqlExpress(buildOptions),
formatError,
schema
);
Actually if you run yarn run graphql:play
, you basically get the similar playground for graphql. If you even want to use graphiql, you need to add the use code inside of the ./server.js
.
http://dev.apollodata.com/tools/graphql-server/graphiql.html#graphiqlExpress
Hm.
Unfortunately what you're linking to is what I'm trying. The code above is from my ./server.js but I can't add a graphql endpoint to it for some reason. That's why I was asking about the routing.
If I follow the guide below it doesn't add graphql to the stack.
http://dev.apollodata.com/tools/graphql-server/setup.html#graphqlExpress
Well, thanks for looking into this. I'll keep trying.
@theednaffattack sorry for late answer I was really busy in these days. Can you show an example what you change or add? Normally it should work if you add your route on server.js
. Doesn't matter it's third-party graphql service or integrated graphql server.
Don't apologize, these are very noob questions and there's only so far you can support folks.
My issue ended up being when to add graphqlExpress to the server instance. In my case I needed to add it before helmet and the route designations get added. So that "fixed" it, totally.
Not that you asked but...
I'm pretty much trying to adapt the howtographql tutorial into RAN and then taking the auth strategy from NAP which is very much like RAN but with a really nice auth setup.
ive done the howtographql too. honestly at this point graphql is too much effort for the limited benefits it brings