Realm offers a great GraphQL API for data fetching and everything was good until I run into pagination. I successufully implemented Offset-based pagination (https://www.apollographql.com/docs/react/data/pagination/), but faced some problems with Cursor-based pagination. Currently, Realm's GraphQL schema does not contain cursor, edges, nodes, pageInfo etc. Is there any way to force Realm generate such things?
Related
I am using mongodb to store items for an auction site
I want to enable fuzzy searching.
Should I query for 1000 results with no parameters then use a js library like fuse.js
Or should I rely on mongodb $regex alone to do the query?
mongodb isn't a great choice for a problem like this. There are lots of great text search utilities available, the most prominent these days being elasticsearch. You'd continue to store your data in mongodb, but you'd keep an elasticsearch instance synced to the mongodb database and perform your searches against elasticsearch. Mongoosastic is a good way to write to both concurrently or Transporter can be used shift the synchronization away from your database persistence flow.
Mongoosastic example:
https://blog.cloudboost.io/sync-mongo-with-elastic-and-save-months-of-development-time-and-cost-d281e0ca8fe4
Some other ways to sync including Transporter: https://code.likeagirl.io/5-different-ways-to-synchronize-data-from-mongodb-to-elasticsearch-d8456b83d44f
Why should I use graphql if I setup a react frontend and mongo db backend?
And Why should i put graphql server between mongo db and react?
Since you didn't mention what is your alternative API style I will just assume it's REST. GraphQL gives you many features a plain old REST api won't have out of the box.
This is probably the best answer listing advantages and disadvantages of both.
You already have validation(via mongoose schemas), but using GQL you can get:
excellent documentation for your API generated for you
avoid underfetching/overfetching on frontend
ability to batch FE requests easily
you can tap into a very rich ecosystem of GraphQL tooling which only gets better as time passes
easier testing-you can just execute your graphql queries on backend even without sending them over the network saving a little bit of performance overhead
I believe you should use GraphQL for any non trivial API, because it adds ton of typesafety and the price you pay as a developer is very low.
I am looking for a Graph database using Scylla or Cassandra as the backend and then expose the web api as GraphQl.
Can you help me verify that I have got the followin stack right:
GraphQl or TinkerPop // Api schema, exposing api
JanusGraph(privious Titan) // Database layer facilitating grap structure
Cassasndra or Scylla
You've pretty much got it right though just to help clarify:
GraphQL is an abstraction designed to help make development/data access a bit simpler for developers. You would have to create a service that translates GraphQL into Gremlin.
The stack you're envisioning looks like:
GraphQL -> Gremlin/TinkerPop -> JanusGraph -> DataStore (Cassandra, Scylla, etc).
As far as the datastore is concerned, JanusGraph is compatible with both Apache Cassandra and Scylla.
I like #MarcintheCloud's answer, just wanted to paraphrase and give my solution to the problem.
GraphQL does not care or depend on any specific database type, KV, Graph, Document, etc and in fact markets itself as being able to fetch data from different sources. So you can create a UI to fetch the latest stock prices from redis, stock history from Mongo and similar stock by name from Elasticsearch. GraphQL will let you abstract that complexity away from your API (but it still exists elsewhere) allowing you to fetch all the data in one go. There is no relation between GraphQL and Graph databases.
Gremlin, in brief, is a powerful graph traversal comparable to what SQL is for some relational databases.
Definitions aside, how I use the both of them is by mapping GraphQL to Gremlin. I have attempted to create a standard around it https://github.com/The-Don-Himself/graphql2gremlin. Basically, it works by interchanging GraphQL arguments between vertexes and edges so a GraphQL query like this
{
users(
following: {
users: {
user_id: "eq(5)"
}
}
) {
user_id
username
bio
}
}
Means fetch a users followers for user_id 5 and get the id, username and bio fields. There are samples of much more complex GraphQL to Gremlin examples and it works perfect for my use case.
The gremlin traversal could look like this
g.V().hasLabel('users').has('user_id', eq(5)).in('following').hasLabel('users').values('user_id', 'username', 'bio')
I also open sourced a sample Twitter Graph in PHP if you want to play around with it https://github.com/The-Don-Himself/gremlin-ogm.
I am developing a Nodejs application and my database is Postgres and I am using Sequelize as my ORM because of its excellent support for migrations.
I am on the lookout for a good REST API generator based on the schema I have defined. There are two main hurdles I am facing and they are that the generators don't do a good job of creating association API routes and lack of ACL support.
On the associations front, my schema has multiple levels of association i.e. for example..
Student.hasMany(Courses);
Courses.hasMany(Subjects);
So ideally the generated REST API should be something like
/student/:student_id/course/:course_id/subject/:subjectId
I found a few projects that are doing this, but are incomplete.
https://github.com/sequelize/sequelize-restful - is good but does not have ACL support
https://www.npmjs.org/package/restizr - is in alpha stage and does not generate API routes for associations.
Is there any module that supports this?
What you were doing here is writing a webservice without a domain model. https://en.wikipedia.org/wiki/Anemic_domain_model Ofc. you have every right to do it, but I wonder if you really understood what a webservice means. https://stackoverflow.com/a/1530607/607033 It is not a database with CRUD HTTP interface normally, though nowadays it is popular doing something this way and call it REST. A response to a REST HTTP request is a viewmodel https://softwareengineering.stackexchange.com/a/425001/65755 and it contains not just data, but a lot of metadata and hyperlinks. A REST API is a special type of webservice with many constraints. https://www.ics.uci.edu/~fielding/pubs/dissertation/fielding_dissertation.pdf http://www.markus-lanthaler.com/research/hydra-a-vocabulary-for-hypermedia-driven-web-apis.pdf Your ORM is used 2 layers deeper in the data layer and it has nothing to do with the presentation layer where your REST API should be. I really wonder why people are making applications, which are doing nothing except serving data directly from the database and use the most inconvenient technology to do it. I guess there are databases nowadays with ACL and REST API support, so all you need is just using them. https://learn.microsoft.com/en-us/rest/api/sql/ Or there was something for PgSQL and Nodejs too around the time you asked this. https://github.com/QBisConsult/psql-api
I am new to mongo, and application design in general, having simply used gems in the past to handle my permalinks (coming from a rails background). I was wondering how best to handle permalinks.
Should you have a collection in mongodb, that links permalinks to their object ids, or is it better to pretty much replace the object id with the permalink acting as the uid? Or should there be some kind of combination of both, where the permalink is simply used in the router and then ids are used in the application internally?
Also some advice on how best to implement these in the application itself as well as the db would be great, I am using expressjs if that's any help.
Thank you.