News for hackers. Stuff that matters.
Re:Ask HN: What tech that's right around the corner are you ... by amirouche on Friday August 04, 2017 @01:41PM (#14930420)
Without doubt, GraphQL is the next technologo I will learn. The idea is so brillant compared to REST. If you are convinced by SQL and in general by Domain Specific Languages, I think you should give GraphQL a try.
Re:Ask HN: What tech that's right around the corner are you ... by tostitos1979 on Friday August 04, 2017 @01:52PM (#14930520)
I'm intrigued ... can you elaborate on the wow factor beyond REST that you see in GraphQL? When I looked at it in the past, it seems to make sense for things that could be represented by graph (e.g. FB's social graph), and graphql allowed you to run complex operations in the backend without fetching each individual node on the client. I clearly missed something?
Re:Ask HN: What tech that's right around the corner are you ... by arstin on Friday August 04, 2017 @02:46PM (#14930943)
This frontend code.

  const ProfileImage = ({ user }) => <img src={user.avatarUrl} alt={user.name} />;
  
  const query = gql`{
    user(id: 3) {
      name
      avatarUrl
    }
  }`

  export const ProfileImageWithData = graphql(query)(ProfileImage);
You can ask for data in the structure the UI expects and only get exactly that data, letting the GQL client handle batching network requests for needs distributed across the whole app, caching, UI updating, etc under the hood. Also does a great job of decoupling product and data management code.
Re:Ask HN: What tech that's right around the corner are you ... by lolive on Friday August 04, 2017 @02:13PM (#14930663)
And if you can also elaborate on why SPARQL and RDF were a major failure, and how GraphQL is different/better?
Re:Ask HN: What tech that's right around the corner are you ... by amirouche on Friday August 04, 2017 @02:24PM (#14930747)
> it seems to make sense for things that could be represented by graph

False, even if there is graph in its name it's not restricted to graph, and that what is great about it compared to things like RDF and SPARQL. Backend data can be stored in key/value store, document, files, RDBMS or whatever. And you will still be able to make it work. AFAIK you write a "translation" layer that interprets a pseudo-JSON file into your data.

AFAIK GraphQL is not good at querying recursive datastructure, it's better at "neighborhood" kind of query, so you can traverse Foreign Keys, but not "indefinitely".

> graphql allowed you to run complex operations in the backend without fetching each individual node on the client.

Yes.

> I clearly missed something?

IDK. For me, GraphQL basically it's an RPC interface particularly suited at "reading" data.

> And if you can also elaborate on why SPARQL and RDF were a major failure, and how GraphQL is different/better?

GraphQL is not tied to particular data layout. I don't know much of SPARQL and RDF actually and don't know why they failed. I am just guessing.

That said, GraphQL it "just" another query language, it's "just" another DSL targeted at querying datastructures. As something that was thought a long time, focused to solve a particular issue.

Re:Ask HN: What tech that's right around the corner are you ... by scottmf on Friday August 04, 2017 @05:55PM (#14932668)
> AFAIK GraphQL is not good at querying recursive datastructure, it's better at "neighborhood" kind of query, so you can traverse Foreign Keys, but not "indefinitely".

That isn't true. You can request data in any shape you want and could theoretically traverse through child nodes indefinitely.

We have many queries which go 5-6 levels deep.

Re:Ask HN: What tech that's right around the corner are you ... by lolive on Friday August 04, 2017 @06:18PM (#14932841)
How do you deal with IDs misalignment between data sources?
Re:Ask HN: What tech that's right around the corner are you ... by scottmf on Friday August 04, 2017 @08:22PM (#14933476)
Could you clarify what you mean? Got an example?
Re:Ask HN: What tech that's right around the corner are you ... by lolive on Saturday August 05, 2017 @02:38AM (#14934502)
Let's say you want to query Wikipedia for village descriptions, and get a map of matched villages from openstreetmap. Would it be a use case where GraphQL could help? Then it would need a "translation" layer for both systems. And joins between datasets would be based (for example) on the couple "country+postalCode". Is it a possible use case of GraphQL?
Re:Ask HN: What tech that's right around the corner are you ... by scottmf on Saturday August 05, 2017 @01:38PM (#14936836)
Could you show me a quick example of what a request and response would look like with REST? I'm still not quite sure what you mean.
Re:Ask HN: What tech that's right around the corner are you ... by lolive on Friday August 04, 2017 @06:16PM (#14932821)
Ok. And the join strategy (i.e IDs alignment) between data sources is defined (declaratively? Programmatically?) in the "translation" layer. Sounds very interesting. I still think the URIs of the semantic web are a better idea, but given the fact that nobody (re)uses them, then why not a "translation" layer.
Re:Ask HN: What tech that's right around the corner are you ... by krono on Friday August 04, 2017 @02:08PM (#14930626)
Great resource for anyone wanting to learn more: https://www.howtographql.com/
Re:Ask HN: What tech that's right around the corner are you ... by X86BSD on Friday August 04, 2017 @01:52PM (#14930530)
I'm encouraged to hear your opinion on it. A friend of mine who turned me on to elixir is a fan of GraphQL as well. So you have pushed me to spend the day reading up on it and experimenting with it. Thank you.
Re:Ask HN: What tech that's right around the corner are you ... by zimablue on Friday August 04, 2017 @07:03PM (#14933088)
I was really not sold by GraphQL, I'm totally down to not use REST as I think that's daft but GraphQL seems to be less powerful than SQL and only really useful if the thing you're querying really is a graph, and not lots of rows of relational data. I do work with data all the time so it's not actually that useful, I wish someone would invent something similar but with a more logical foundation (joins and aggregations and stuff, not only through ugly plugins). Maybe like datalog although I never learned that enough to find the payoffs.
Re:Ask HN: What tech that's right around the corner are you ... by sixdimensional on Friday August 04, 2017 @07:54PM (#14933347)
Personally, I believe that someone needs to build some kind of a scalable, security-hardened SQL interface that can be queried directly from the browser using actual SQL. Part of that need involves federated data from multiple services/data sources. We already have a query language that can even handle nested values (see ISO SQL:2016 standard), why not just adapt it for use in the browser?
Re:Ask HN: What tech that's right around the corner are you ... by zimablue on Saturday August 05, 2017 @03:33AM (#14934621)
I don't really like SQL either, it's hard to generate and doesn't support any abstractions, it might be an OK target format for some amazing query generator.
Re:Ask HN: What tech that's right around the corner are you ... by scottmf on Friday August 04, 2017 @08:51PM (#14933597)
I'm genuinely surprised by the number of people on HN who seem to know very little about what has been safe to call the successor to REST for quite some time.

Forgive me if this sounds hyperbolic, but unless you have unusual or strict requirements, building a new app in 2017 REST-first is most likely a terrible mistake.

Let me clear up some misconceptions I see in almost every HN comment thread on GraphQL:

1. GraphQL isn't more suited to Graph databases. Your data sources can be a mix of relational DB, NoSQL, key value, a REST API, or anything else.

2. n+1 has always been a solved problem in GraphQL thanks to DataLoader[1], a query batching utility which coalesces calls to your data sources from different parts of your app, specifically to avoid n+1.

3. It's unquestionably production-ready, battle-tested, has a real spec and official reference implementation, and it's probably the safest bet you can make at this moment in an industry as fickle as this.

With GraphQL you simply write your schema, define types and relationships, and you’re then able to request data in almost any shape you wish, with very little extra work. This is invaluable during development.

If you have a list of recent comments with author names, and later decide to show an avatar alongside the name, you don’t need to write any extra code on the server. You add an extra line to your query (or component’s fragment) on the client.

The same goes for any field, any relationship, no matter how complex the resulting shape. If you wanted a comment author’s follower’s comments’ likeCounts, you still don’t need to write another line of server code.

This makes it stupidly simple to rapidly prototype new features, try out new layouts, and means you can share a single API endpoint between mobile apps and desktop site without sending useless data to one or both.

There have been many occasions when we simply wouldn't have had the time to implement a feature correctly with REST, particularly when we might not even know what data we'll want until we begin developing the feature and get a feel for how it works.

It doesn't just save server dev time either. On the client side there are libraries like Apollo[2] and Relay which take care of fetching data, caching, normalization, and you should almost certainly use one (I recommend Apollo) unless you have a good reason not to. Writing fetch calls and managing your store manually is just going to be a huge waste of time.

And the spec is more than queries and mutations. It's subscriptions, live queries, and more [3]. Real-time data is a first-class citizen of GraphQL, and the two most popular front-end libraries have official implementations of subscriptions (with live queries in progress).

GraphQL is elegant, has a well-designed official spec, great DX and just plain makes sense. But it's really something you need to try out for yourself (preferably on a real project) to see just how great it is.

If you’re planning to build something new with REST, seriously, reconsider. There's a slightly higher upfront cost to using GraphQL (particularly if you're new to it), but once you settle into it you'll be glad you did.

Useful tools and resources:

- GraphiQL[4] - an incredibly useful tool for running queries on your GraphQL API

- Graph.cool[5] - BaaS for quickly prototyping a GraphQL API

- Apollo Launchpad[6] - Try out GraphQL server code in your browser

[1] https://github.com/facebook/dataloader

[2] https://github.com/apollographql/apollo-client

[3] https://dev-blog.apollodata.com/new-features-in-graphql-batc...

[4] https://github.com/graphql/graphiql

[5] https://www.graph.cool

[6] http://launchpad.graphql.com

Re:Ask HN: What tech that's right around the corner are you ... by vladimir-y on Saturday August 05, 2017 @02:53AM (#14934529)
OData appeared before the GraphQL with the similar ideas.
Re:Ask HN: What tech that's right around the corner are you ... by scottmf on Saturday August 05, 2017 @01:02PM (#14936641)
Cool, which ones? I think the concept of requesting a response shape was inevitable. It's one of those "obvious in hindsight" ideas.

You see many "GraphQL is similar to x, and x failed" comments on here, but I'm not sure x ever came close to where GraphQL is at the moment.

Good ideas fail sometimes. E4X failed, but JSX and its variations are game-changers.

Re:Ask HN: What tech that's right around the corner are you ... by vladimir-y on Tuesday August 08, 2017 @01:08PM (#14959926)
> Cool, which ones?

Forming data requests on the client/consumer side.

> JSX and its variations are game-changers.

don't be so sure

Re:Ask HN: What tech that's right around the corner are you ... by transcranial on Friday August 04, 2017 @02:08PM (#14930623)
GraphQL has been a breath of fresh air -- you can tell a lot of thought went into its design and implementation.
Re:Ask HN: What tech that's right around the corner are you ... by thisisforyou on Friday August 04, 2017 @02:13PM (#14930659)
I built a GraphQL API earlier this year. The learning curve can be a little awkward coming from REST, but once you get the hang of it GraphQL is super fun. Can't recommend it enough. Enjoy!
Re:Ask HN: What tech that's right around the corner are you ... by sp527 on Friday August 04, 2017 @04:02PM (#14931702)
By what factor does using GraphQL accelerate development time?
Re:Ask HN: What tech that's right around the corner are you ... by FullMtlAlcoholc on Friday August 04, 2017 @09:11PM (#14933686)
I couldn't put a number on it, but it greatly accelerates development on the front-end. The API call gets you back all the data you need, only the data you need, in the format or structure that you need.

If there were GraphQL for Spotify's API and you wanted an artist's discography, you don't have to make multiple calls to endpoints and work through huge objects where 90-95% of the data is not needed.

For the front-end, it's a no-brainer. I've read that it is a bit more involved on the server-side but Apollo seems to be making great tooling for it.

Re:Ask HN: What tech that's right around the corner are you ... by BatFastard on Friday August 04, 2017 @09:34PM (#14933768)
4.3875321