Skip to content

Instantly share code, notes, and snippets.

@daniele-zurico
Created June 12, 2018 19:11
Show Gist options
  • Select an option

  • Save daniele-zurico/ff53e986163a71b284efecf40db6800c to your computer and use it in GitHub Desktop.

Select an option

Save daniele-zurico/ff53e986163a71b284efecf40db6800c to your computer and use it in GitHub Desktop.
export const pubsub = new PubSub();
const MONGO_PORT = 27017;
const MONGO_URL = "localhost";
const dbName = "graphExample";
export const CLIENT_ID =
"YOUR_ID";
export const client = new OAuth2Client(CLIENT_ID);
// help to debug mongoose
mongoose.set("debug", true);
mongoose.connect(`mongodb://${MONGO_URL}:${MONGO_PORT}/${dbName}`);
const schema: GraphQLSchema = mergeSchemas({
schemas,
resolvers
});
// GraphQL
const server = new ApolloServer({
schema,
context: async ({ req }: any) => {
if (!req || !req.headers) {
return;
}
const token = req.headers.authorization || "";
const checkToken = await userController.findOrCreateUser(token);
if (!checkToken.hasOwnProperty('authorized')) {
return {user: checkToken, authorized: true};
}
return checkToken;
},
tracing: true,
});
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment