11 ms·
GraphQL Working Draft
- hartror 11y agoSome background: https://facebook.github.io/react/blog/2015/05/01/graphql-introduction.html https://facebook.github.io/react/blog/2015/05/01/graphql-int...
- AdamCraven 11y agoWith a talk from earlier this year that describes an implementation: https://facebook.github.io/react/blog/2015/02/20/introducing-relay-and-graphql.html https://facebook.github.io/react/blog/2015/02/20/introducing...
- binarymax 11y agoWhy not have the query in JSON? Now you need a new parser. EDIT: Thanks for all the replies, all of them very good points, and clearly show that JSON is not the most elegant option for a complex DSL.
- colinramsay 11y agoThere are certain things that are a bit more elegant if you can have a custom query language. One example: query UseFragment { luke: human(id: "1000") { ...HumanFragment } leia: human(id: "1003") { ...HumanFragment } } fragment HumanFragment on Human { name homePlanet } You could definitely have some JSON to represent this but it might turn out to be more trouble than it's worth...
- agrothberg 11y agoWhat about YAML?
- andreasklinger 11y agothe query contains by far more logic than should be put into json you could map it to json - but technically you could map everything to json - doesnt mean you decrease complexity the parser is the lowest problem of parsing and optimizing those queries i'd assume
- monk_e_boy 11y agoReadability I guess. The new syntax looks pretty good to me. A little heavy on the (( and )) but very obvious as to what is being asked.
- voyou 11y agoI wonder how important readability is in this case, though. How likely is it that this language will be written (or read) directly by people, rather than generated and consumed by programs? The potential bugs in generators and parsers (think SQL injection) seem like a real cost, which I would have thought would outweigh the benefit of improved readability.
- leebyron 11y agoGraphQL is definitely designed to be written by developers, not by tools. We have a feature called query variables that provides the same strong typing to input values for queries that need to fetch different data dynamically.
- seivan 11y agoI'm guessing you might want some 'small' parts of logic, like the unary operation. Guessing!
- jackmoore 11y agoI believe Netflix's Falcor, which seems very similar to Relay, uses JSON.
- kolev 11y agoWhere in the world is Falcor? We keep hearing about it, we saw the presentation, but this is all we've got and it's nothing: https://github.com/michaelbpaulson/Falcor https://github.com/michaelbpaulson/Falcor
- nutate 11y agoI had made a comment on twitter that the ref: concept basically throws json off the indecidability cliff in terms of parsing. They opened an issue for it apparently, but you can see the graphql rfc has specific anti-cycle checks, which is super important.
- gniquil 11y agoIt's sad that you capitulated. I agree with your original point more. Is this thing really flexible, composable, and implementable? How long do we have to wait for people to provide solid implementations on top of all the popular programming language and database backends? Feels like SQL all over again. Someone will be writing layers on top of this in javascript in the frontend and ruby/python/javascript/etc. in the backend. Then we are in another ORM hell. (Perhaps I am being too pessimistic here, it could very well be great, but I have some serious reservations...)
- dandellion 11y agoMongoDB did JSON queries. After having useed it I don't think it's a good idea at all.
- vjeux 11y agoLee Byron is talking about it at React Europe right now, here's the live stream (which supports play back): https://www.youtube.com/watch?v=UclvvqNtNNo https://www.youtube.com/watch?v=UclvvqNtNNo
- Murkin 11y agoThere was a comment on the original blog post that while they (Facebook) use GraphQL they still fall back to Flux for some of the data handling. Was this solved ? Did they manage to handle all the data needs of their apps with GraphQL or is it still limited to certain areas ?
- HeyImAlex 11y agoThey are orthogonal; graph ql is for fetching data and is supposed to be an alternative to writing a new backend endpoint for every ui-thing that needs some slice of data, flux is a pattern for organizing data flow in the UI.
- darknoon 11y agoI think you mean falling back to "FQL," the old SQL-like syntax, since Flux is more of a client architecture thing (paired with GraphQL). FQL has some holdouts in legacy code, but the vast majority of the iOS app is using GraphQL. There are a bunch of tools built around using it, and it's the "right way" these days. Maybe a year or more ago ago, the notifications tab was using FQL. It makes sense to convert things since the risk in switching is outweighed by a reduction in server CPU, network bytes transferred, and ability of tools to understand the code. When we built Paper, we did notifications on GraphQL because there wasn't the risk of breaking something. You can almost certainly handle all of your 'data needs' with GraphQL... :D
- woah 11y agoI think the OP meant Flux. I also read about it being used to store things that are not being persisted.
- darknoon 11y agoFair enough. In that case, yeah, GraphQL is about the server communication and doesn't specify a particular application architecture. There's usually some data you want saved locally and not persisted to the server, though that's not very common in facebook, since eg preferences are meant to work across devices.
- cetra3 11y agoWould love to see a more robust server backend for this, but I am assuming it's still a long way off. A standard is a very good start. I notice the license is BSD, but is this patent encumbered?
- spicyj 11y agoThere's a JS server provided: https://github.com/graphql/graphql-js https://github.com/graphql/graphql-js.
- xtrumanx 11y ago> It is not a fully standalone GraphQL server that a client developer could use to start manipulating and querying data.... The only “backend” we have targeted for this early preview are in-memory stubs in test cases. > To that end the target audience is not the client developer, but those who have or are actively interested in building their own GraphQL implementations and tools. I guess I'm kind of happy that FB are releasing something regarding GraphQL since introducing it in February. I just thought they got busy with React Native and forgot about everything else they hyped up back in February.
- applecore 11y agoUnlike with RESTful APIs, a server basically only needs a single endpoint that parses and responds to GraphQL commands. This isn't as far off as you suppose to be the case.
- stevepike 11y agoThe trickiness will come in handling authentication for all the nested resources (e.g., user X can only see public photos for user Y, and can't update them) and generating efficient queries to a relational datastore. Coming up with a clean architecture for that actually seems like a fun project!
- applecore 11y agoIt's a good thing that relational databases solved the problem of generating efficient execution plans for ad-hoc queries about thirty years ago—with SQL.
- applecore 11y agoFinally! It's exciting to see a serious challenger to the cult of REST.
- davedx 11y ago> cult of REST Is this a thing?
- ZitchDog 11y agoYes, we have regular meetings where we worship a statue of Roy Fielding and debate the merits of HAL over JSON Hyper Schema. Long live HATEOAS!
- Siyo 11y agoYes, here's one of their masterpieces: https://github.com/rails/jquery-ujs/blob/master/src/rails.js#L206 https://github.com/rails/jquery-ujs/blob/master/src/rails.js...
- nathancahill 11y ago:O
- jaegerpicker 11y agoSo, I haven't had enough time to really dig into the spec but it doesn't seem like the language has any kind of insert or update type of feature. Perhaps I just missed it though. But if it doesn't it seems like you would need a pretty large dataset to make this worth it, right? I mean for any kind of a change event you still need to support a standard REST API, as this really only replaces the GET operation. Am I missing something on it? I certainly not saying it's not a cool idea or base to build from, just want to make sure I'm not skipping over an important piece.
- colinramsay 11y agoGraphQL seems to go hand-in-hand with Relay, and there's a talk on mutations in Relay here: https://speakerdeck.com/laneyk/mutations-in-relay https://speakerdeck.com/laneyk/mutations-in-relay That might provide the answers you're looking for. It's worth reading all the notes as I think this is the best resource for understanding how React + Relay + GraphQL really works. You basically use GraphQL with a payload (the data to mutate and the mutation type) to select what to change and what data is returned after the change.
- dschafer 11y agoGraphQL doesn't prescribe a particular approach to mutations; it allows the server developer to specify what mutations are available. For example, at Facebook we have a storyCreate mutation, and a friendRequestAdd mutation. Mutations are just top level fields, but with side effects; because they are fields, the client sends up a selection set with the mutation. This allows the client to receive whatever data it needs to refresh, as the response to the mutation. GraphQL was originally designed for reads, but we added write support to solve the parallel problem we were having with writes: different clients wanted different data back from the server after they performed a write. GraphQL gave us that capability.
- jaegerpicker 11y agoAwesome, thanks for the explanation. My team is rolling out an REST API currently and I've always wanted a Linq/SQL type of interface to REST API's. I could definitely see GraphQL evolving in that kind of direction. Some amazingly cool open source tech coming out of Facebook these days.
- sinwave 11y agoLol - the code example seems to imply that Zuckerburg's user id is 4.
- prezjordan 11y agoIt is :)
- deleted 11y ago[deleted]
- samhoggnz 11y agoThat's because it is 4! https://www.facebook.com/4 https://www.facebook.com/4
- revskill 11y agoWho is 1,2,3 ?
- ci5er 11y agoYou could always try... - https://www.facebook.com/1 - https://www.facebook.com/2 - https://www.facebook.com/3 My guess (and there may even be apocrypha about it), is that these were old registration test accounts that didn't survive the first Zuckerbergian purge.
- leebyron 11y agoCorrect. SQL auto increment keys plus test accounts resulted in Zuck being 4.
- sanderjd 11y agoAs a ruby programmer, my gut reaction was that this had something to do with bugs caused by the object id of `nil` being 4. But of course that's not the case :)
- 11y ago
- thechao 11y agoI always enjoyed XPath as a lighter-weight mechanism for querying trees. It turns out that there are a set of pretty straightforward changes that can be made to XPath to have it support graphs. To wit: add a notion of a named 'traverser' (depth- vs breadth- search; pre-, in-, or post- order; how nodes are marked; etc.); then, change the notion of 'parent' to 'in' and 'child' to 'out'. XPath can then be implemented as syntactic sugar on top of this lower level "Graph Path" mechanism. I'd always intended to convince my advisor to have the grad students do a graph-path implementation on top of boost::graph, in his generic programming course; alas, never happened. The 'masters' version of this would be to do a lazily evaluated version of graph path in C++ and Haskell to "teach them the students a lesson".
- porker 11y agoHow does this fit in/differ from Netflix's Falcor? https://twitter.com/falcorjs https://twitter.com/falcorjs
- leebyron 11y agoThey are attempting to solve similar problems: describing data needs on a client in a way that integrates well with how the data is used, and fulfilling those requirements efficiently. Falcor uses some different primitives to accomplish the task, focusing on connecting together Observables, whereas GraphQL queries are written in a small query language. Falcor is a super interesting project and we've gotten to swap notes a couple times.
- porker 11y agoAwesome, thanks. I watched the Falcor presentation and had my mind blown; looking forward to a similar explanation of GraphQL.
- barakm 11y agoI've been looking forward to this! One question; it appears as though the types and schema are passed with every request (eg https://github.com/graphql/graphql-js/blob/master/src/graphql.js#L30 https://github.com/graphql/graphql-js/blob/master/src/graphq... ) -- I assume part of the reason for this is versioning/sharing the schema, but is it always external, does the server ever know the schema a priori -- what's the thinking around this design decision? (It's a plausible idea! I'm just curious on the what and why)
- dschafer 11y agoIt's passed to that function in the reference implementation, but a server would probably create a helper function that runs a query for a particular schema. For example, you can just pass a query to Facebook's GraphQL endpoint (without specifying a schema), and it will run the query on the Facebook schema.
- barakm 11y agoThis is also reasonable; but an example of how schema get created and discovered by a client would be a nice extension to the spec. :)
- leebyron 11y agoPerhaps that code is a bit misleading. The schema itself is defined and provided by the server. The idea being that a server would build up it's type definitions, and then call into graphql's executor providing both the schema the server defined (in code) as well as the query the client provided (as a network request)
- smizell 11y agoGot curious about how the spec is built. Source said: > Built with spec-md http://leebyron.com/spec-md/ http://leebyron.com/spec-md/
- tristanz 11y agoAre there any plans to release the Relay (client side) component of this?
- TheMakeA 11y agoJoe Savona says August.