Graphql-js: GraphQL integration with Cassandra

Created on 9 Jan 2017  路  11Comments  路  Source: graphql/graphql-js

In our legacy application we already implemented our own Generic query language to fetch the data for what we need.Considering the standard we tried to adopt GraphQL instead of our own stuff API .Eariler we used MongoDB as storage engine and written wrappers API for query parsing,validation etc.Considering the distributed nature we moved to Cassandra DB.

Is there any better integration or APIs with Cassandra DB.Is there any frameworks to convert GraphQL queries to Cassandra queries.Otherwise it is going to be very difficult or complex to implement query parsing ,validation and writing lot of CQL stuff.

Most helpful comment

If you mean parsing and validation in terms of business rules and logic, this is within the business domain and each business should be figuring that layer out for themselves. There are plenty of libraries to help with this, but it is up to you to select which one to use (or create your own). This image shows you where GraphQL would sit as an API. What you are asking for is the blue area and AFAIK, this hasn't been anything built out to be a standardized back-end (yet).

10-01-_2017_15-19-15

Scott

All 11 comments

This might be of interest.

http://codefoundries.com/developer/cassandra/cassandra-meet-relay.html

Since GraphQL is supposed to be a thin layer API between your business logic and your front-ends, I highly doubt you'll find specific implementations for any particular database.

Scott

it is going to be very difficult or complex to implement query parsing ,validation and writing lot of CQL stuff

Can you give an example of an input GraphQL query, the resulting query against the DB, and why you consider it to be very difficult?

EDIT: removed cassandra-meet-relay link since the commenter above cited it already

I already seen cassandra-meet-relay.Other than using cassandra-driver I didn't find any useful information from that link.There are no proper examples for easy integration.

query RootQuery {
accounts(skip: 0,limit: 13,sort_field: "account_number",sort_order: "descending",filter:"{'account_number': { '$not': { '$gt': 4522 } }}"){
account_number,
account_name
}
}

What do you consider is "easy integration"?

Scott

I mean If there is an API for parsing,validation from Graphql to Cassandra then it will be easy to implement for kind of appliations

If you mean parsing and validation in terms of business rules and logic, this is within the business domain and each business should be figuring that layer out for themselves. There are plenty of libraries to help with this, but it is up to you to select which one to use (or create your own). This image shows you where GraphQL would sit as an API. What you are asking for is the blue area and AFAIK, this hasn't been anything built out to be a standardized back-end (yet).

10-01-_2017_15-19-15

Scott

Thanks smolinari for your detailed response.The query parameters(sometimes it include so many filter conditions) need to extracted for each field and add it for CQL(Cassandra query language).It will be painful for each query.The CQL queries will be scattered with lots of condtions.

I already seen cassandra-meet-relay.Other than using cassandra-driver I didn't find any useful information from that link.There are no proper examples for easy integration.

query RootQuery {
accounts(skip: 0,limit: 13,sort_field: "account_number",sort_order: "descending",filter:"{'account_number': { '$not': { '$gt': 4522 } }}"){
account_number,
account_name
}
}

This example query seems very close to the database layer. You already mentioned that you migrated from MongoDB to Cassandra. If you expose too many persistence layer details at the API layer, you will have trouble moving off Cassandra or joining it with other data sources (perhaps some sort of distributed cache?), or even doing in-memory data manipulation that CQL can't handle. This is one of the reasons why Relay, for example, defines a more generalized "Connection" concept that can map to any underlying data source(s): https://facebook.github.io/relay/graphql/connections.htm.

If you're absolutely sure you want to design your GraphQL API like this, then it seems you're going to have to roll up your sleeves with Cassandra. GraphQL binding layers also exist for other DBs, check out: https://github.com/calebmer/postgraphql

@robzhu - I agree with your analysis of exposing too many persistence layer details at the API layer level. That is also why I am not too certain postgraphql is what @sudheerj is looking for either. It is missing exactly what he is looking for, business logic and validation. It is purely persistence layer details at the API layer. 馃槈

Edit:
This library is a start to what I would consider a business logic layer.

https://github.com/xpepermint/rawmodeljs

Scott

@sudheerj I think there's a good amount of info for you here, but nothing specific that we can do to help you in terms of feature work on graphql-js. Closing the issue, re-open if you believe if it is unresolved.

Thanks Robzhu and smolinari for your comments.Relay connection concept is just talking about pagination model.But most of my complexity lies in fields conditions with lots of operators.For example, all possible CQL conditions might appear http://www.datastax.com/dev/blog/a-deep-look-to-the-cql-where-clause To apply each condition on persistance layer might cause scattered code,lots of parsing,validations etc.

If it is a MongoDB then I can format and pass all filter conditions as Single JSON object as input parameter.So Iam looking for any integration APIs or CQL query generated APIs based on GraphQL Schema.

I will treat that logic as utility work instead of business logic :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

swist picture swist  路  4Comments

sudheerj picture sudheerj  路  3Comments

galki picture galki  路  3Comments

bhough picture bhough  路  3Comments

matthewgertner picture matthewgertner  路  4Comments