Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

APIs Introduction to GraphQL Making Changes with Mutations Mutating with Input Object Types

Phaneendra N
Phaneendra N
1,218 Points

Can graph QL query be written inside existing java script client code?

Hi, With the traditional (javascript ajax)-[calling]->(Rest endpoint)-[calling]->(database) pattern. Where will Graph QL fit into? Or is it completely a different component that will replace some of these boxes?

Cheers! Phaneendra

1 Answer

Ari Misha
Ari Misha
19,323 Points

Hiya there! Say you're using React framework as your client-side. React have many libraries just to perform server-side rendering in React component like next.js, threejs etc and if you're using a superset of JavaScript like TypeScript instead of Babel, makes your life a lot easier. Now they call it GraphQL RESTful 2.0. REST API has some pros and cons, and since its just a design pattern, it's very opinionated.

Most of the devs implement the server-side code in store in Redux or your state management library. Why is that? This is 'coz you wanna separate your provider with your consumer. Here provider is Redux/MobX and the consumer is React component. This pattern has lots of advantages to it like it makes it easier to test and debug, plus you wouldn't wanna mix async code with your component.

How to understand GraphQL? Consider GraphQL one of 'em obnoxious kids, who only asks for delicious stuff in the lunch at School. He is very picky and since everyone knows hows he like so they know how to deal with him beforehand by givin' him whatever he wants. With REST API you get the whole data from the endpoint but with GraphQL you can very picky and you could even provide your custom options like limits, size, and likewise stuff. You only get whatchu define in the schema. So yeah it doesn't crowd your application with data. I hope it helped!

~ Ari