DEV Community

Cover image for GraphQL + Mongodb. The easy way.

GraphQL + Mongodb. The easy way.

Álvaro on June 02, 2019

EDIT: Seeing the repercussion this post had I'll make one updated, using Prisma, new GraphQL features and will be available for whatever database y...
Collapse
 
remorses profile image
Tommaso De Rossi • Edited

You should check out mongoke, it automatically generates the whole graphql api based on the mongodb database schema, it also handles authorization, relay pagination and more.

Collapse
 
damiisdandy profile image
damilola jerugba

mongoke-sharingan
mind the pun

Collapse
 
flutterstack profile image
Flutter-Stack • Edited

I was trying out this blog . when I was tried using npm to install the packages I got error. yarn is working fine.

apollo-server-core/dist/utils/isDirectiveDefined.js:11
return typeDef.definitions.some(definition => definition.kind === language_1.Kind.DIRECTIVE_DEFINITION &&
^

TypeError: Cannot read property 'some' of undefined

Error throwing at below lines:

const server = new ApolloServer({
typeDefs: schemas,
resolvers,
context: async ({req}) => {
if (req) {
const me = await getUser(req);
return { me, models: { userModel, postModel }}
}
},
});

Collapse
 
kappaxbeta profile image
kappaxbeta

Nice Job :-)

Collapse
 
kayatechindia profile image
kayatechindia

Thanks

Collapse
 
kaisheng1 profile image
kaisheng1

Thanks for this really good content! I just have to ask, how would you handle logout though?

Collapse
 
alvarojsnish profile image
Álvaro

Hi, thank you too!

We have many ways to handle logout:

We could do something as Django does and saving the token in the database, then checking it and deleting it when the user wants to logout.

But, I'm more oriented to frontend development, so I would handle this on the frontend, we would store the token in the storage or something then at the time we logout we just delete the token from the storage.

There are a lot of ways of handling this actions and all are valid, you just need to find the one that fits you!

Collapse
 
kaxi1993 profile image
Lasha Kakhidze

Thanks Alvaro

Collapse
 
nbgooch profile image
nbgooch

👍

Collapse
 
saidy_barry profile image
Saidy Barry 🇬🇲

hello, can u help me with the error? Error: Cannot find module './user'

Collapse
 
alvarojsnish profile image
Álvaro

Hi Saidy, maybe you are trying to import a module that doesn’t exists, is in another directory, or has a different name! Check it

Collapse
 
stronkberg0510 profile image
stronkberg0510

hello. how would i get deleted data from delete mutation. can you help?
tried findOneAndDelete() and it returns null;