8 ms·
How to GraphQL – A Fullstack Tutorial for GraphQL
- nikolasburk 9y agoHey everyone We're super excited to finally launch this resource that we've worked on together with amazing members of the GraphQL community! The goal of How to GraphQL is to provide an entry-point for all developers to get started with GraphQL - no matter what their background is. The whole site is open-source and completely free to use! If you want to contribute a tutorial because your favorite language is still missing, please get in touch with us! Here's the official announcement blog post on the Graphcool blog: https://www.graph.cool/blog/2017-07-11-howtographql-xaixed1aa9/ https://www.graph.cool/blog/2017-07-11-howtographql-xaixed1a... If you find a bug or another problem, create an issue or submit a PR on the GitHub repo: https://github.com/howtographql/howtographql https://github.com/howtographql/howtographql Follow us on Twitter to be informed about new content that's added to the site: https://twitter.com/graphcool https://twitter.com/graphcool
- zimme 9y agoAwesome! I'll share it with GraphQL Stockholm.
- shroom 9y agoAwesome resource! I've been playing around with GraphQL on a Node/React+Apollo project and found it very useful and fun to use. My background with backend is mostly PHP. Any good plans on adding PHP guide to backend section or is there no good GraphQL-server/implementation for PHP?
- jasonbahl 9y agoI can't speak to the entirity of your question, but the last part I will address: "is there no good GraphQL-server/implementation for PHP" There are 2 good PHP servers: https://github.com/Youshido/GraphQL https://github.com/Youshido/GraphQL https://github.com/webonyx/graphql-php https://github.com/webonyx/graphql-php It seems like the majority of the graphql-php community has rallied around the Webonyx implementation, including myself for my WPGraphQL project, a free open source WordPress plugin that brings a GraphQL API to WordPress (https://wpgraphql.com https://wpgraphql.com) As the maintainer of WPGraphQL, I'd be interested in adding a section to the HowToGraphQL resource specific to using GraphQL with WordPress, but haven't had any official discussions with the maintainers of the project yet. There are also implementations for Laravel and other projects, using that library.
- shroom 9y agoThanks a lot this was exactly what I was looking for :) sorry if the question was a bit fuzzy.
- chaaau 9y agoHeyhey! I heard a lot about GraphQL before, but I'm not quite sure what it is. Is it similar to Neo4j?
- lghh 9y agoSome of the introductory material in the resource will fill you in on what GraphQL is.
- nikolasburk 9y agoHey! That's actually a pretty common misconception people have about GraphQL when they first hear about it - however, GraphQL definitely is not a Graph database (as is Neo4j). In fact, it's not even a database technology, despite sharing the same suffix with SQL! GraphQL is a query language for APIs - so, the closest you could get is to say that GraphQL is an API technology! It defines a specific request/response-format for client-server communication that's extremely flexible, simple and efficient. GraphQL is also independent of the transport protocol that's used (though mostly that's HTTP today). If you have a good idea about what an API is, you can read the second chapter of "How to GraphQL" where we highlight technical differences between GraphQL & REST: https://www.howtographql.com/basics/1-graphql-is-the-better-rest/ https://www.howtographql.com/basics/1-graphql-is-the-better-...
- soflete 9y agoI have recently started learning React and I am following the lessons in www.hotwographql.com. I am trying to decide which GraphQL library to use for the practical exercise. Should I go for Relay or Apollo? Also, I have been working as an Android developer for the last couple of years, and I was wondering how similar are the React and Android implementations of Apollo.
- nikolasburk 9y agoHow to choose between Relay & Apollo is one of the most common questions people ask when they get started with GraphQL! In general, it definitely depends on your project and what you're optimizing for. Relay is very mature and heavily optimized for performance, however, it's not very easy to understand and comes with a notable learning curve. Apollo on the other hand is a community-driven effort to build a very flexible GraphQL client that still offers a powerful and intuitive API. I'd actually suggest you try to go through both tutorials on How to GraphQL and see which one feels better for you :) PS. In case you weren't aware of it - the second GraphQL Radio episode had Lee Byron and Joe Savona (both from Facebook/Relay) as well as Sashko Stubailo and Jonas Helfer (both from Apollo) as guests: www.graphqlradio.com
- ismaelbej 9y agoI've found that Apollo stack is more user friendly for learning. I didn't try in a production environment, but unless there's a huge difference in performance I'd use Apollo.
- Dirlewanger 9y agoI've only given a cursory look into it, and with regards to building a JSON API in Rails (of which the many extant standards and their Rails libraries are still immature), is this just another fad, or an actual API standard that has staying power? It seems like the latter, but given that it's Facebook-backed, as soon as they get tired of it, they could pull a Google on it.
- pselbert 9y agoThere is a practical, functional GraphQL spec that has multiple client and server implementations. Regardless of whether Facebook continues to develop clients or maintains stewardship of the spec, GraphQL has a lengthy future ahead.
- jacobwg 9y agoI have personally found it to be a practical, useful API standard that provides benefits over a JSON API in Rails. I wrote an article about some of the benefits a couple of years ago: https://0x2a.sh/from-rest-to-graphql-b4e95e94c26b https://0x2a.sh/from-rest-to-graphql-b4e95e94c26b. You can architect "traditional" Rails APIs to get some of the similar benefits, but GraphQL works out of the box with existing client libraries.
- dschafer 9y agoWe've been using GraphQL at Facebook in production for almost five years now, and it powers a huge amount of our iOS/Android app's API traffic. We also did a comprehensive revisit of the core concepts when we open sourced it in 2015, and we heavily use tools like GraphiQL internally. I can definitely assure you that Facebook's support/usage of GraphQL isn't a fad.
- deleted 9y ago[deleted]
- Huvik 9y agoNice job! Great source for learning Graphql :)
- Cieplak 9y agoJust wanted to give a huge shout-out to PostgREST: https://postgrest.com https://postgrest.com https://github.com/begriffs/postgrest https://github.com/begriffs/postgrest You can get many of the benefits of GraphQL using postgrest's resource embedding: https://postgrest.com/en/v4.1/api.html#resource-embedding https://postgrest.com/en/v4.1/api.html#resource-embedding We're using it in production. PS: To be clear, you can't expose it directly to your users. We wrap it in a proxy service that provides authentication and authorization, and parses and transforms the users' URL queries destined for PostgREST. We also apply some transformations to the data coming back from PostgREST, such as encoding our internal UUIDs. It may sound complicated, but it's actually only about 200 lines of Erlang.
- ruslan_talpa 9y agowhere are you using it? (and you can even get GraphQL on top of it :P https://subzero.cloud https://subzero.cloud)
- ice109 9y agoi don't understand how one would use this? obviously you're not just exposing this api to users right? are you just using it as a substitute for an orm or data access layer in your own app?
- ruslan_talpa 9y agoI bet they ar doing exactly that, exposing the api supported by PostgREST :) https://github.com/subzerocloud/postgrest-starter-kit/wiki/PostgreSQL-Concepts#views https://github.com/subzerocloud/postgrest-starter-kit/wiki/P... Edit: seems they are not, ... oh well :)
- ice109 9y agobusiness logic in sql seems like a bad idea (especially since you can't connect it to other services? or can you make ajax requests in sql?).
- notheguyouthink 9y agoWhat I've not understood about GraphQL is how to map it to My/Postgre/etc SQL. The info about resolving specific fields seems .. complex, and difficult to optimize tom say, reduce SQL calls. Is there a library that, say for Golang, helps translate a GraphQL Query into SQL statements to actually get the data?
- bdibs 9y agoI haven't played with the Golang server yet, but with Node you just set the resolve to something like: resolve (root, args) { return Db.models.post.findAll({ where: args }); } (sorry for the lack of markup, I don't know how to do anything here yet) Here's a blog post specifically for Golang: http://alexandrutopliceanu.ro/post/graphql-with-go-and-postgresql/ http://alexandrutopliceanu.ro/post/graphql-with-go-and-postg...
- ruslan_talpa 9y agohttps://subzero.cloud https://subzero.cloud (1 query, optimal for any number of levels) https://github.com/stems/join-monster https://github.com/stems/join-monster (1 query, overhead for more than 2 levels) https://github.com/facebook/dataloader https://github.com/facebook/dataloader (best case, 1 query per level, in sequence )
- dobs 9y agoYou might be interested in postgraphql: https://github.com/postgraphql/postgraphql https://github.com/postgraphql/postgraphql Otherwise it depends on your GraphQL implementation and what DB adapters or ORMs they support. For example, `graphql-ruby` includes a generator for a Rails-compatible GraphQL schema.
- bdibs 9y agoI just read more and played with GraphQL just the other day, and it's really an amazing and powerful tool. Save requests and bandwidth, no need for explicit version control, and to top it off an easy to use syntax? Sign me up! I'll definitely be using this in future projects.
- alexchamberlain 9y agoIt's fantastic to see a tutorial that separates the frontend from the backend. As someone that _doesn't_ work in web technologies, it can be tough to follow basic tutorials or take them to the next level when you're trying to understand node, npm and webpack, as well as the concept you want to learn: GraphQL, which although hyped, does look like it brings substantial value to the table.
- aaron-lebo 9y agoIf you are a starter don't worry about it at this point. A good REST API and understanding of how that works is a really good foundation for web development that you can take with you from language to language and project to project. This is a cool but still relatively niche technology.
- alexchamberlain 9y agoMy interest in GraphQL has a few different layers: it's a different querying paradigm, in the same way that REST and RPC paradigms are different; what are the pros and cons? How do you optimise services throughout your stack to handle load that is - in theory - of an unknown pattern, but in practice, will be of certain shapes? Furthermore, if we divide SOA/microservices into several tiers - separating UI services from backend services - does GraphQL fair better than more traditional paradigms? How do we "merge" GraphQL schemas? Whilst I agree it's niche now, not many new paradigms come along and not many of them have so many questions that can be asked, so there has to be something interesting there.
- ai_ia 9y agoExactly what I was looking for. Thanks team behind this.
- renke1 9y agoI recently started using GraphQL and I love. The best thing about GraphQL is having a standard interface for queries (and more) and all tools that built upon it (such as Apollo). To name a few existing and upcoming (?) features from Apollo: Query batching, real-time updates (WebSockets + subscriptions), caching, optimistic UI, polling, pagination, live queries and many more. Also, GraphiQL is pretty cool, too, basically Swagger for free.
- j_s 9y agoI am curious to here about any experiences implementing a GraphQL backend in production on .NET (non-Core) + SQL Server. Even React feels left out here in my neck of the woods.
- justforFranz 9y agoThe GraphQL has a diversity problem. :)
- sayurichick 9y agoI like USING GraphQL (for existing services), like Github's API. However, 99% of the tutorials on graphql , this one included, fail to show a real life use case. What I mean by that is a working Example of a SQL database from start to finish. So this tutorial was very cool, but not very useful. Just like the rest of them. I've yet to find a recent tutorial that covers full stack node.js + PostgreSQL/MySQL + whatever front end. It's always MongoDB or only covers the concepts of GraphQL.
- slaymaker1907 9y agoThe problem with using a relational database with GraphQL seems like you need to solve the object relational mismatch. I think in that case you'd be better off writing a library for parsing SQL then putting a secure layer over it that limits what SQL is allowed. Ideally, you'd be able to just handle these security issues with the database directly through views and permissions, but as far as I know there is no database with enough permissions controls for this.
- ruslan_talpa 9y agothere is, PostgreSQL https://blog.2ndquadrant.com/application-users-vs-row-level-security/ https://blog.2ndquadrant.com/application-users-vs-row-level-... (and saying GraphQL can't work with databases I think is wrong, it's the same as saying OO languages are not a good fit for relational databases)
- slaymaker1907 9y agoThanks for the info!
- vosper 9y agoWhat about using GraphQL implies that you're trying to map objects from the database? As far as I know you can just query for the fields you want (with whatever joins you might need, or subqueries, or calls out to some other system) and return them to the client.
- slaymaker1907 9y agoI've looked a bit through the GraohQL syntax. While it is an immense improvement over plain Rest, I dislike the abuse of JSON as a query language. I think it would be better if it were a true DSL like SQL or some sort of Lisp. Instead of allPersons, I think it would be cleaner and easier to understand as (all Person) Which makes the generic nature of "all" explicit.
- djmashko2 9y agoThe thing is that the "all" is actually _not_ generic in this case. The GraphQL server implementor has to specify a field called that specifically.
- schrockn 9y agoGreat job. Awesome to see all the focus on documentation and conceptual explanations. Clear messaging and spreading understanding are just as important as the tech.
- yks 9y agoIs GraphQL substantially better than OData (created 5 years earlier)?
- miclill 9y agoGraphQl really seems to be a step up from REST. The complexity of the client/server-libraries will increase but that's ok. If I look at graphql-java I see: - "The Java implementation of DataLoader is unfortunately still in the making." - "While graphql-java does parse subscription requests, its support at the moment unfortunately stops there" Seems it's not ready yet.
- xmatos 9y agoWhy use GraphQL? Why not simply expose one endpoint that takes a sql data parameter, queries the db and return the result set as json? Yes, you'd have to setup db security to allow those db commands to run only selects and restrict which tables are allowed to be queried. How can using a new json query language, without any server libraries targetting relational databases be better than that? How much work would be envolved to implement this on the server side and for what, exactly? to allow frontend devs to query without exposing separate endpoints? Client-server applications should not run business code on the client. The only code that should run on the client is the UI's. Sorry, this is simply wrong.
- arcticfox 9y agoWhat happens when your backend isn't SQL? Then you'll need to accept a different query language as well. Wait - maybe those could be abstracted into a single query language? Ah, it's GraphQL! To your other points: * no matter what you do to expose an API you have to set up security * there are already server side solutions that help enormously with implementing your own endpoint * I don't see the logic behind your client-server opinion. You seem to say that the server should be defining the data that the client needs.
- xmatos 9y agoRegarding the last point, yes, that's what I'm saying. And it's not a matter of opinion, but of decades of computer engineering best practices. Your app's UX will depend on how much code runs on the client. It can vary from a dumb terminal, like classic web applications, where everything runs on the server, to smart or rich clients, where some code do run on the client, but is always related to the UI. In a client-server application, your app's logic should always run on the server. I've worked on desktop client-server apps where the application logic was on the client and the server was mainly the database. It works, but you might end with clients with different versions trying to access the DB and you don't want that. That's what server validation means. You should never trust clients. You shouldn't build a web app, which is a client-server app, entirely on the client. It's like reverse best practices. It will bite you. Regarding having something else than sql, how much effort would be necessary to build a graphql server library that abstracts whatever you have on the server? Would you build something and release it to your clients with that level of maturity? And for what?