What is the difference between GraphQL and mongoose? - node.js

I am reading a book about GraphQL, and they claim that one strong point of GraphQL is selecting a field from the database. See sample below:
On this image, they selected just the title from the movies on the database. I can do the same using mongoose, using "select".
Could I say that mongoose is already GraphQL?

One is a query language that can be resolved by reaching into databases and gathering data, the other is a friendly wrapper that helps you interact with MongoDB, a NoSQL database.
You cannot say that it is already GQL because it does not deal in GraphQL language, it deals in JS queries. They are different languages with different syntaxes.
You might write a resolver for a GraphQL query using Mongoose, but they are still 2 separate things.

After I have asked the question, I gave some thoughts on the matter, indeed, as said zero298, they are two different things. Here, they build a app using both technologies, and justify the reasons it is better.
An excerpt from the aforementioned article:
"GraphQL is a technology that helps developers across the board to build more robust software more quickly. The ability to request all of the information you need in a single request is a game-changer. It has simplified my backend development of APIs for consumption by mobile and web applications that would normally rely on RESTful APIs. A normal RESTful API may have several endpoints for various entities (e.g. users, submissions, etc.); with GraphQL, you can get all of this information in a single go using GraphQL’s query language, also known as GQL."
I adding this extra answer as so if somebody falls into the same trap, they can easily get out!
Related question:
Do I need mongoose with graphql?
GraphQL with mongoose

Related

Would it be good idea to store mongoose documents in AsyncLocalStorage?

I have a web server which is made specifically for an app. Some of the services get very complex in terms of calling a lot of functions across multiple services and each of them querying multiple models. Would it be good idea to save the queried documents of each request in AsyncLocalStorage to reduce the time taken for querying?
So, I would check if document is present in ALS if yes then use it else fetch and save it there before using.
I tried to find references related to this but didn't find anything. Which led me to think maybe it is not such a good idea after all. But then querying the same document again and again over different services doesn't make sense either.

Loopback vs. NestJS - Loopback out of the box GraphQL-like querying with REST support is nice. Is something similar also achievable with NestJS?

We're very familiar with IBM's Loopback and we're exploring/comparing NestJS as an alternative.
First and main topic: One feature that has always been an overall pleasure to work with is Loopback's built-in REST API's for its models together with the GraphQL-like querying that is supported both in the TypeScript API and as part of the REST API's themselves. It's been a pleasure to be able to include as many levels of depth of related entities as we like, add in other filtering and limit/scope to include certain fields. (This gives a gist of the feature: https://loopback.io/doc/en/lb4/Include-filter.html)
Is this possible to achieve in the NestJS world? I see a RelationalQueryBuilder for NestJS that is built-in (https://orkhan.gitbook.io/typeorm/docs/relational-query-builder) but I don't see it connected to a built in REST API and it looks a bit less sophisticated with its relations querying capability. Here are some decorators for CRUD REST in NestJS, but without the querying support (https://github.com/nestjsx/crud/wiki/Controllers#api-endpoints).
Also mature polymorphic relations support in Loopback seems like a strong differentiator for Loopback vs. an emerging extension for polymorphic relationships in NestJS (https://github.com/bashleigh/typeorm-polymorphic... thank you bashleigh!). Any success/thoughts opinions here?
How is working with MongoDB with NestJS (and TypeORM or Mongoose are the options)?
It seems like the first feature and main topic (built-in REST API's with fluent querying) may be one that really sets Loopback apart.

REST mapping to GraphQL

We are currently developing an online shop for products in node.js. We use GraphQL in our backend. Now we would like to offer REST for our customers in addition to GraphQL. What would be the fastest and most effective solution for this problem?
When designing REST APIs one should start from database tables aka persistent entities and there are too many ways and frameworks.
When you have GraphQL already in place you may want your REST API to be somewhat similar, but I bet that made things more complicated, while pure REST evolved as simple HTTP implementation.
In face HTTP standard and REST standard have the same author(s).

How to write a "middleware" in Node.JS

Apologies if this question is too general. This is not an invitation for "opinion-based" answers. Unfortunately, at this stage of the project and with my limited knowledge in this space, I just need some guidance from more experienced people.
In a large company project, I have a web service that is based on NOSQL data models. I have little influence over the design of this service. Due to the data structure, when overseeing the development of a large and complex mobile app (for multiple platforms), I noticed that sometimes it was necessary to make calls to multiple endpoints in sequence to get the required information.
For example: there is the need to first call an endpoint sending certain parameters to get a user ID, then use that user ID to get details about the user. The system cannot deliver the user details on the first call. This leads to complex data parsing and background processes on the clients.
To simplify mobile development, we now want to build a "middleware" layer that simplifies the API for the mobile clients. The app would call the middleware as the single point of entry, the middleware would call the existing endpoints to gather the necessary data and deliver the result back to the client.
For example, the client would ask for finding a certain user and delivering certain attributes of this user (e.g. the first names of all friends of the user) with one API endpoint. The middleware would need to make many calls to the backend: search for the user, use the result (user ID) to get details and friends of the user, use the delivered friends' userIDs to gather data about the friends. Then the middleware would package the information and deliver it back to the client.
Initial recommendations from colleagues indicate that Node.JS would be a good framework for developing this type of functionality in a maintainable, scalable way.
OK, I know how to run a simple server and manage routes on a node system, but how would you organize this project, e.g. the file structure? Which components would you encapsulate. Are there any frameworks on top of Node that would help with a task like that?
I am not looking for "opinions", just for some insightful recommendations based on experience or knowledge. Feel free to down-vote this question after you have stated what you do not like about it and have asked specific questions to clarify (I will comply as soon as possible). Thanks.
how would you organize this project, e.g. the file structure?
I have described my filesystem layout in my express code structure github repository, which is also posted as a stackoverflow answer here
Which components would you encapsulate.
I think it's OK to encapsulate the interface to each backing API as a "model" or "service" type module. If you are making database queries, encapsulating those either into models or at least modules of related queries is OK.
Are there any frameworks on top of Node that would help with a task like that?
Yes, many. I prefer express as the basic web app framework with hapi being the other strong choice. There are other options both smaller (more 1-purpose libraries) and larger (closer to full-featured frameworks) like loopback or sails.js.

What potholes are there Using Graphql with RethinkDb?

As I understand it's possible graphql with rethinkdb. You can use graphql to query really any data set as its just the middleware really. What issues do I need to watch out for in this implementation? Server will be node.js in my case.
Documentation / examples of others doing this seam lacking.
I'm using GraphQL together with RethinkDb and don't see any particular problems in using them together compared to an implementation of a rest api or using mongo etc.
Here are two github projects using GraphQL and RethinkDb (the first one is more lightweight):
Isomorphic Material Relay Starter Kit
meatier

Resources