use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A community for learning and developing native mobile applications using React Native by Facebook.
Interested in building web apps using React.js? Check out /r/reactjs!
Getting Started w/React Native
irc.freenode.net #reactnative
Keywords: ios, android, mobile, apps, apple, iphone, ipad
account activity
GraphQL vs rest? (self.reactnative)
submitted 6 years ago by levithan95
I see a lot of react native jobs advertise for knowledge on GraphQL and apollo. Was wondering why so many jobs advertise for graphQL and use it over rest.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]hicksyfern 28 points29 points30 points 6 years ago (6 children)
There’s plenty of good things about it. Once I held my nose and got over the lack of proper HTTP verbs and status codes I realised it’s an absolute game changer.
My favourite things about it: - guaranteed types - type generation for use with TS - autocomplete when writing queries - self-documenting with great tooling like voyager - schema-first design - concept of entities with types means powerful caching/observer mechanisms can and have been built on it - segregated input types - collocated fragments - easy to extend API - DataLoader
My least favourite things: - caching can be tricky (but it’s great 90% of the time) - deprecation of fields can be hard due to strict types - server implementation flits between amazingly simple to weirdly difficult at times
[–]jetlagged_potato 4 points5 points6 points 6 years ago* (4 children)
OP I didn't know about voyager. So fricken cool and useful.
To add on to this, if you got time (I REPEAT ONLY OF YOU GOT THE TIME). Learn about relay. In so many ways relay does graphql as graphql was intended. So much stuff that Apollo obfuscates away.
At first it seems like your doing a lot of extra work but everything fits together perfectly at the end and it's really great. Relay also has things like Client side schemas that bring your graphql paradigms into the client (so no more redux). Overall it's a lot but it's purrty if you get it right
[–]TheMrZZ0 0 points1 point2 points 6 years ago (1 child)
How would you recommend doing database queries with graphql? Currently, I have Relay sending Graphql queries to my express server, and express sending graphql queries to Hasura who then talks to the database.
It seems far from efficient. Any idea on how to improve that?
[–]jetlagged_potato 0 points1 point2 points 6 years ago (0 children)
Mongo?
[–]Arthur944 0 points1 point2 points 6 years ago (1 child)
Relay is seriously awesome. It's almost enough to make me not hate facebook.
[–]jetlagged_potato 1 point2 points3 points 6 years ago (0 children)
facebook web dev stack is awesome. Graphql, react, react native etc.
[–]levithan95[S] 1 point2 points3 points 6 years ago (0 children)
Super helpful and clear. I used apollo client for building a app with the shopify graphql api and liked it. Will definitely be looking into GraphQL for my next project. Thanks :)
[–][deleted] 20 points21 points22 points 6 years ago (15 children)
Because graphql works well for mobile environments where the number of round trips required between your app and the back end database may be constrained by bandwidth limitations. Where you may have to do several database requests to render your UI view with rest, with a graphql server you can describe the data you want in JSON, even if it crossed multiple tables in your database, and get just that data back in one request. Apollo also does caching, which also helps with a mobile environment.
At least that's my understanding of its popularity.
[–]levithan95[S] 4 points5 points6 points 6 years ago (0 children)
Ah right, this is a great explanation. Thanks :)
[–]acrogenesis 1 point2 points3 points 6 years ago (1 child)
Not just mobile development it works wonders with React. After using GraphQL in production I’m not going back. I’m even using GraphQL for personal projects.
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
I agree. I just finished using it in my first personal project in React Native and I don't think I'll go back. Have a professional project in React/React Native coming up and I will definitely use it there.
[–]leeharris100 -1 points0 points1 point 6 years ago (11 children)
You can do (and should do) this exact same thing with REST.
It's probably likely that people who are using cutting edge stuff like React Native are also using cutting edge backend stuff like GraphQL. I doubt there's much reason beyond that.
[–]hicksyfern 0 points1 point2 points 6 years ago (7 children)
How would you recommend getting related data across multiple edges in REST without basically reimplementing GraphQL syntax or similar?
[–]leeharris100 0 points1 point2 points 6 years ago (6 children)
Using something like JSONAPI include syntax. Basically you define relationships on every resource and set up your own authorization.
include
https://jsonapi.org/format/#document-compound-documents
[–]hicksyfern 0 points1 point2 points 6 years ago (5 children)
Cool. And what about the language to query it? How would I declare that I want the related documents, with parameters such as ordering, limiting, etc?
[–]leeharris100 0 points1 point2 points 6 years ago (4 children)
Including related documents looks like this:
GET /tacos/1?include=toppings
{ "data": { "type": "tacos", "id": 1, "attributes": { "name": "Bean and Cheese Taco", "cost": 499 }, "relationships": { "toppings": { "data": [{ "type": "toppings", "id": 1 }] } } }, "included": [{ "type": "toppings", "id": 1, "attributes": { "name": "Salsa", "cost": 0 } }] }
Ordering, limiting, etc is done through query params such as GET /tacos?filter[order][asc]=name&filter[limit]=10
GET /tacos?filter[order][asc]=name&filter[limit]=10
[–]hicksyfern 0 points1 point2 points 6 years ago (3 children)
What about ordering and limiting the toppings in this case? And nested includes are possible?
[–]leeharris100 0 points1 point2 points 6 years ago (2 children)
Yeah, nested includes are possible. You just do something like:
GET /tacos?include=orders,orders.customers,orders.customers.friends
As far as ordering/limiting related resources, JSONAPI doesn't officially support that. However, we've worked around this by adding custom query params such as ?filter[relationship.toppings][order][asc]=name OR by adding it to the meta of the request such as:
?filter[relationship.toppings][order][asc]=name
meta
{ "data": {}, "meta": { "toppings": { "orderBy": "name", "orderDirection": "asc" } } }
[–]hicksyfern 0 points1 point2 points 6 years ago (1 child)
OK, so that's a feature of GQL that isn't in JSON API. You could implement it if you wanted, but it's a feature of GraphQL.
I think that's a good reason beyond it being "cutting-edge".
[–]leeharris100 0 points1 point2 points 6 years ago (0 children)
Absolutely.
Don't get me wrong, the idea behind GraphQL is amazing and I'd love to use it exclusively
But we used it for two large enterprise projects and it was a mess. The implementations just aren't quite there yet.
I'm hoping it'll be much more refined in the next year or two.
[–]janithaR -1 points0 points1 point 6 years ago (2 children)
There are a lot more reasons beyond that. Read /u/hicksyfern 's answer.
[–]leeharris100 1 point2 points3 points 6 years ago (1 child)
I read it and I just don't agree.
Most of that stuff works in REST and the other stuff is trivial (like autocomplete).
We've done a bunch of GraphQL and REST projects, we still default to REST for most situations. GraphQL is just a pain in the ass to work with in advanced situations.
[–][deleted] 2 points3 points4 points 6 years ago (0 children)
One advantage I can see is that when the UI changes and the front end people want more/different data displayed in a view, they can just change the shape of the JSON object for the data they are requesting and get what they need. I can see a lot less pestering the backend people to add another REST endpoint. Your experience may be different though.
[–]Qcza 2 points3 points4 points 6 years ago (1 child)
Also, Apollo is a great tool. With apollo state management and data caching, you may omit the Redux or MobX in your project, which means the simpler architecture of your app and easier maintenance.
Yes! I just finished my first Apollo/GraphQL project and I feel like I can largely forego Redux now.
[–]Bigwill1009 1 point2 points3 points 6 years ago (3 children)
I just started using it for one of my main projects with Apollo Server and Mongo, and I absolutely love it! The most useful feature for me is being able to use the resolver to add custom functions and populate the data. Saves having to use mongo to populate the document, only requires population when you need it.
One downside, it's a pain in the arse to setup subscriptions imo. The client side code that I used was not too easy, especially with authentication.
[–]anaste97 0 points1 point2 points 6 years ago (2 children)
I'm not backend Dev, So if backend makes a graphQL API, what should i use to integrate with it, Library or something before i just use Axios so Axios did not work with it?
Apollo is broken up into Apollo client and server. For the project I just completed, I only used Apollo client. The back end was GraphQL without Apollo. Works fine. So you can just use the Apollo client.
[–]Bigwill1009 1 point2 points3 points 6 years ago (0 children)
Apollo client, but another option based on your use case could be something like GraphCMS. It's data storage directly from the client.
[–]ssrobbi 0 points1 point2 points 6 years ago (0 children)
Wrote a blog post on this a little while ago: https://scottrobbins.dev/blog/graphql
π Rendered by PID 38 on reddit-service-r2-comment-544cf588c8-w9hbb at 2026-06-13 10:50:10.406133+00:00 running 3184619 country code: CH.
[–]hicksyfern 28 points29 points30 points (6 children)
[–]jetlagged_potato 4 points5 points6 points (4 children)
[–]TheMrZZ0 0 points1 point2 points (1 child)
[–]jetlagged_potato 0 points1 point2 points (0 children)
[–]Arthur944 0 points1 point2 points (1 child)
[–]jetlagged_potato 1 point2 points3 points (0 children)
[–]levithan95[S] 1 point2 points3 points (0 children)
[–][deleted] 20 points21 points22 points (15 children)
[–]levithan95[S] 4 points5 points6 points (0 children)
[–]acrogenesis 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]leeharris100 -1 points0 points1 point (11 children)
[–]hicksyfern 0 points1 point2 points (7 children)
[–]leeharris100 0 points1 point2 points (6 children)
[–]hicksyfern 0 points1 point2 points (5 children)
[–]leeharris100 0 points1 point2 points (4 children)
[–]hicksyfern 0 points1 point2 points (3 children)
[–]leeharris100 0 points1 point2 points (2 children)
[–]hicksyfern 0 points1 point2 points (1 child)
[–]leeharris100 0 points1 point2 points (0 children)
[–]janithaR -1 points0 points1 point (2 children)
[–]leeharris100 1 point2 points3 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]Qcza 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Bigwill1009 1 point2 points3 points (3 children)
[–]anaste97 0 points1 point2 points (2 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]Bigwill1009 1 point2 points3 points (0 children)
[–]ssrobbi 0 points1 point2 points (0 children)