Can I use GraphQL for mongoDB or mySQL? - mysql

I have started learning GraphQL and found that GraphQL is an awesome query language.
However I wonder if I can use GraphQL for existing databases such as mongoDB or mySQL.
Also please explain about prisma.
Is prisma a cloud database or something?
Edit:
TL;DR:
GraphQL can be used with any database as long as the data satisfies the type-strict qualification. Prisma is a node.js/typescript ORM library and works great with GraphQL.
Looking back to this a bit old question, I noticed that the question was so dumb and a bit too wide. So I've decided to add some more thoughts as I'm now quite familiar with GraphQL and Prisma. Hope this could be a help for new developers who are starting to learn GraphQL and Prisma.
GraphQL is a query language that we can use to interact with the API.
Like the REST API, GraphQL is another type of API format where we can use Queries to get data and Mutations to update data.
As the REST API doesn't depend on the database type, GraphQL can also be used with any database as long as the data can be formatted into type-strict models.
On the backend side tho, you need to implement the GraphQL interface that reads data from the database and sends as the Query response, and updates the database with the data from the Mutation.
Prisma on the other hand is a node.js/typescript ORM library - similar to mongoose or sequelize. The benefits of using Prisma is that it auto-generates the TS models and makes it much easier to interact with the database in typescript.
As GraphQL and Prisma are both strict in type usages, they match quite well. Also, Prisma provides an exclusive interface for GraphQL implementation, so you can easily write GraphQL interface with Prisma.
Please check out here for more information on the combination of GraphQL and Prisma: https://www.prisma.io/graphql
It was a long edit, but hope this helps.

As it was mentioned on previous post - yes, you can.
An example, if you backend application wrote on .NET stack - you may use, guess two, main libs that really tested and guys use it in real projects (google GraphQL.Net and second lib should be spelled almost the same)
But, both of these libs give you only processing of graphql queries and describe schemes ("accounts {id name}" means you should define resolver which returns data from db or another data source)
Most of guys use EF (EntityFramework) as a data-adapter between GraphQL and db. But, from my point of view it's useless, especially, if we are talking about get data from db and that may be thousands requests.
We implemented component that based on light-weight DB lib (to almost all popular dbs like MSSQL, Postgresql, MySQL or Elasticsearch), gives ability to configure GraphQL scheme very easy and provide main features like sort, pagination and complex filter.

Yes, you can use it with existing DB.
Prisma is an ORM layer build using GraphQL server, it abstracts away the database and let you interact with the database using GraphQL query. It currently supports MySQL, MongoDB, AWS RDS & PostgreSQL. It's not a database, but you can host it on the cloud.
Typically, you need another GraphQL server that inside it resolvers will call Prisma's GraphQL server. This GraphQL server is the one that is called by the client.

Related

I am getting error with native query when I shift from mysql to mongodb [duplicate]

After seeing this image:
http://2.bp.blogspot.com/_T-uXeKcGTnM/TIdoKBGwk9I/AAAAAAAABcs/CLW3_cRlN78/s1600/tumblr_kxovt0VLZy1qappj8.png
I wonder is exists any tool for translating SQL querys into MongoDB map/reduce query model??
Larger version of the image: http://rickosborne.org/download/SQL-to-MongoDB.pdf
Update to the question asked in Jan 2011:
A couple of sites exist now to convert sql to mongodb.
Convert MySQL Queries to MongoDB Syntax
http://www.querymongo.com/
And
Convert sql to mongodb
http://klaus.dk/sqltomongodb/
The simple anwser? No.
The slightly more complex anwser is some people have had luck translating more complex SQL to Mapreduce functions ...
http://rickosborne.org/blog/index.php/2010/02/08/playing-around-with-mongodb-and-mapreduce-functions/
http://rickosborne.org/blog/index.php/2010/02/19/yes-virginia-thats-automated-sql-to-mongodb-mapreduce/
However, that said ... generally speaking you might as well learn mapreduce properly because if the data is in MongoDB already ... you'll really need to know how to properly query MongoDB to get anything meaningful done!
MongoDB has wonderful and helpful docs http://www.mongodb.org/display/DOCS/Advanced+Queries
As well as an easy to use online tutorial: http://try.mongodb.org/
The simple answer: Yes. Hibernate OGM - JPA for NoSQL.
JPA is Java API for mapping objects to data stores.
It includes JPQL, a query language similar to SQL which adds the OOP concepts. It's not SQL, but you don't want pure SQL - that was designed for the relational paradigm.
Hibernate OGM proposes to simplify the programming model by embracing JPA/Hibernate APIs and semantics to store data in NoSQL stores like JBoss Enterprise Data Grid instead of the traditional RDBMS. (source)
Also see this Hibernate OGM: JPA for NoSQL talk by Hardy Ferentschik
Recently I happened to see this website mongoquery.com, you can try it.
You can use free sql to mongodb converter like: https://rapidapi.com/ariefsam/api/easy-sql-to-mongodb-aggregation/
Just to add to the last comment
re:The simple answer: Yes. Hibernate OGM - JPA for NoSQL.
JPA is Java API for mapping objects to data stores.
It includes JPQL, a query language similar to SQL which adds the OOP concepts. It's not SQL, but you don't want pure SQL - that was designed for the relational paradigm.
There is a company called UnityJDBC that has released a JDBC driver for Mongo that allows you to run SQL queries against mongo in any java application that supports JDBC.
you can download this driver free at
http://www.unityjdbc.com/mongojdbc/mongo_jdbc.php
hope this helps
You can also http://teiid.org which gives full range of SQL based access to MongoDB. You can use SQL through JDBC/ODBC or use REST/ODATA based access to MongoDB. Teiid uses MongoDB's aggregation framework to provide advanced SQL MongoDB query conversation.

MySQL or JSON view base on Node.js app and API

I know this kind of question is ask in many different ways, and I know that's annoying for answering so much same question, but as I google it, search in Stackoverflow I can't really find a nice answer, the answer I'm asking is based on views like easy for answering API request (which is in JSON format) and in the view of I'm designing Node.js APP
So here is my case
I'm building my own Node.js application somehow like a CMS or blogging platform so imagine I need a place to store all my posts data where should I store in a MySQL database or External JSON file it's quite confusing I personally prefer JSON since it's nice looking (?) but it's quite hard to use fs.writefile and fs.readfilesync to update data in the external JSON, but I don't know how to make an API that will give the post data by MySQL database since the API is in the JSON format
If I have any misunderstood please tell me
if you want to store data in json then go form nosql database like mongodb. Postgresql latest versions also supports JSON data types.
Maybe what you need is ORM module, for example sequelize
It works with MySQL/Postgres, and offers you APIs like MongoDB.

Write Breezejs data source provider with Nodejs for MySQL

I would like to use Breeze with NodeJS and MySQL. Unfortunately, so far I could find no examples of this. I have seen that there is an example of NodeJS + MongoDB. Now I try to analyze the MongoDB provider (mongoSaveHandler.js - [npm install breeze-mongodb]?) to write my own provider for MySQL. Unfortunately I could not find any documentation on how such a provider must be established.
The provider should be able to deal with complex data and navigation properties (one-to-many, etc.) and also save/delete/update them properly in the MySQL database.
The following is an example of how the database structure might look like:
Database Image
My questions are now:
Is there already an example with Breeze (+NodeJS) and MySQL that I could use?
Is there a documentation/sample how to write a own data source provider?
If I'm on my own, what should I look for when I create my provider?
There are plenty of Web API+EF+SQL samples, the Node+MongoDB sample you've already seen, a Ruby+SQL sample, and even a NoDB (and 3rd party data) sample ... but no Node+SQL sample yet.
These docs aren't spot on for your use case, but they will likely point you in the right direction:
ToDo Server
The docs are for Web API+EF+SQL, but good detail on how everything is wired together.
MongoDB
The MongoDB docs as well as the Zza! sample are pretty good about showing how they configured the Node server (to talk with MongoDB, sure, but you can see the process all the same).

mysql framework for node.js

Is there any mysql framework for node.js?
I found only https://github.com/felixge/node-mysql but this only allows executing "raw" mysql statements. I am looking for some tool which will provide easier way of manipulating mysql database and data.
Especially I need pagination and joining mechanisms...
I am not looking for a full framework because I am using restify to build RESTapi - just need a module to retrieve/save data to mysql db. So I need only "model" part of MVC ;).
It sounds like you may be looking for an ORM. If that's the case, you can take a look at Sequelize. It will let you define your objects, and then simply 'save' and 'fetch' them, without really having to worry about how its doing it.
You can look at db-mysql module. This module provides api for creating queries. Here is module GitHub page.

Mix of MySQL and Mongodb in an application

I'm writing a web application using PHP/Symfony2/Doctrine2 and just finishing up the design of the Database. We have to import these objects (for ex. Projects, Vendors) into our database that come from different customers with variety of fields. Some customers have 2 fields in the project object and some have 20. So I was thinking about implementing them in MongoDB since it seems like a good use for it.
Symfony2 supports both ORM and ODM so that shouldn't be a problem, Now my question is how to ensure the integrity of the data in both databases. Because Objects in my MySQL db need to somehow be linked to the objects in the MongoDB for integrity issues.
Are there any better solutions out there? Any help/thoughts would be appreciated
Bulat implemented a Doctrine extension while we were at OpenSky for handling references between MongoDB documents and MySQL records, which is currently sitting in their (admittedly outdated) fork of the DoctrineExtensions project. You'll want to look at either the orm2odm_references or openskyfork branches. For this to be usable in your project, you'll probably want to port it over to a fresh fork of DoctrineExtensions, or simply incorporate the code into your application. Unfortunately, there is no documentation apart from the code itself.
Thankfully, there is also cookbook article on the Doctrine website that describes how to implement this from scratch. Basically, you rely on an event listener to replace your property with a reference (i.e. uninitialized Proxy object) from the other object manager and the natural behavior of Proxy objects to lazily load themselves takes care of the rest. Provided the event listener is a service, you can easily inject both the ORM and ODM object managers into it.
The only integrity guaranteed by this model is that you'll receive exceptions when trying to hydrate a bad reference, which is probably more than you'd get by simply storing an ID of the other database and querying manually.
So the way we solved this problem was by moving to Postgres. Postgres has a datatype called hstore that acts like a NoSQL column. Works pretty sweet
UPDATE
Now that I'm looking back, go with jsonb instead of json or hstore as it allows you to have more of a data structure than a key-value store.