
BlueChip – An ORM-like syntax for retrieving data from GraphQL or JsonAPI - mfpiccolo
https://github.com/mfpiccolo/blue-chip
======
Cieplak
I’ve been using PostgREST as an ORM for about two years now. I know it may
sound unconventional, but it’s definitely worth a try, especially if you’re
building HTTP APIs. Here’s an example query:

    
    
        /investors?select=name,investments(id,founders(name,address(city,country)))&investment.exit=gt.1000000.00
    

[https://postgrest.org](https://postgrest.org)

~~~
pwaai
wow thanks! I will be using this instead.

~~~
mfpiccolo
Just and FYI BlueChip and PostgREST serve different purposes.

------
artpar
Hey this looks great. So this would work out of the box for something like
daptin[1] on server side ? It exposes
[http://jsonapi.org/](http://jsonapi.org/) compliant CRUD APIs. If so, I would
suggest getting it listed at
[http://jsonapi.org/implementations/](http://jsonapi.org/implementations/) by
sending them a PR

[1] [https://github.com/daptin/daptin](https://github.com/daptin/daptin)

~~~
mfpiccolo
I will check that out today and add it to the list of integrations if it does
(it should if it complies with JsonAPI)

------
devj
Check out OrbitJS -
[https://github.com/orbitjs/orbit](https://github.com/orbitjs/orbit) . They've
built something similar.

------
millerm
I'll just throw these out there as an alternative, or in addition to:

[https://www.apollographql.com/docs/link/links/rest.html](https://www.apollographql.com/docs/link/links/rest.html)

[https://www.apollographql.com/docs/link/links/state.html](https://www.apollographql.com/docs/link/links/state.html)

The "apollo-link-rest" API makes it very easy to map, then query, your JSON
APIs as a GraphQL service. So, no more mangling different query approaches for
a client.

Then, simply add "apollo-link-state" to query/mutate local data using GraphQL
as well.

This allows you to have 1 query/mutation language for both remote and local
client state. This is much easier to deal with than adding yet another API to
access your data.

Another positive is that you just might find yourself with the ability remove
some redux boilerplate too as your local state can now be managed via Apollo's
HOCs.

So, after writing this... What would be nice is to perhaps have the BlueChip
API have an adapter layer that would allow it to read from something like the
Apollo cache. This would allow for the implementation of resolvers on the
client side to allow more fine grained control of the data being returned in a
query (query parameter for filtering, cursoring and the like).

~~~
mfpiccolo
Thanks! I will check those out.

Abstracting the adapter layer is in the roadmap both for the specs (GraphQL,
JsonAPI, nested or custom) and for the state managment (Redux, Mobx, Unstated,
React setState, Pain JS Object, etc.)

------
33degrees
Looks good! I've been using json-api-normalizer[1] and redux-object[2] to do
something similar. The ORM functionality is a nice difference though, I'll
have to try it out.

    
    
      [1] https://github.com/yury-dymov/json-api-normalizer 
      [2] https://github.com/yury-dymov/redux-object

------
jaequery
this just makes me wonder why we don't just pass in SQL on the API calls, ala
graphql.

~~~
mcphage
Because then you’re building your database schema into your public API, making
it difficult to vary either.

~~~
smallnamespace
Conversely, if your API isn't public, tightly coupling your stack together may
be worth the tradeoff of brittleness vs. development speed.

