{"id":3852,"date":"2019-05-29T01:14:56","date_gmt":"2019-05-29T01:14:56","guid":{"rendered":"https:\/\/www.solutionstreet.com\/blog\/?p=3852"},"modified":"2019-05-29T01:14:56","modified_gmt":"2019-05-29T01:14:56","slug":"you-really-should-be-using-graphql","status":"publish","type":"post","link":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/","title":{"rendered":"You Really Should Be Using GraphQL"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"576\" src=\"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2019\/05\/rowingguy3title3.png\" alt=\"\" class=\"wp-image-3853\" srcset=\"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2019\/05\/rowingguy3title3.png 768w, https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2019\/05\/rowingguy3title3-300x225.png 300w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><p><strong>Origin of GraphQL<\/strong><br><\/p>\n&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Back in 2012, Facebook was dealing with an issue that many of us software developers who build products with multiple front-ends (web and mobile) must address. How can we build a server component Application Programming Interface (API) that works seamlessly with both mobile and web applications? How can we have the same API calls with the same data response easily handled by web and mobile and be performant? The result of Facebook having difficulty with these questions was the creation of <a rel=\"noopener noreferrer\" href=\"https:\/\/graphql.org\/\" target=\"_blank\">GraphQL<\/a> by Facebook with a specification, open source code, and a community. GraphQL not only provides a solution for the different requirements of web and mobile, but also the ever increasing need to have a somewhat generic API access to systems.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n&nbsp;\n<p><strong>GraphQL vs. Rest<\/strong><\/p>\n&nbsp;\n\n\n\n<p class=\"wp-block-paragraph\">Many of us have used Representational State Transfer (<a href=\"https:\/\/restfulapi.net\/\" target=\"_blank\" rel=\"noopener noreferrer\">REST<\/a>) for a while and understand that it\u2019s an architectural style. REST refers to a set of principles like statelessness for developing APIs. It uses <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hypertext_Transfer_Protocol\" target=\"_blank\" rel=\"noopener noreferrer\">HTTP<\/a> verbs\/methods like GET, PUT, POST to link resources to actions.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you take a banking application with an object like a banking transaction you may have the following REST API call (endpoint) which returns the Transaction along with the name of the associated Account (i.e., attributes of its parent). &nbsp;<br><\/p>\n\n\n\n<pre lang=\"javascript\" line=\"1\">GET \/transactions\/1234\n{\n \"date\": \"2019-05-12\",\n \"amount\": 100.50,\n \"account\": \n {\n   \"name\": \"My Checking\"\n }\n}\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This object (or resource) is coupled with the way you retrieve it. Here we are retrieving a banking Transaction with the id of \u201c1234\u201d based on the URL pattern and we have defined on the server that when we retrieve the Transaction we will bring along with it the name from the associated Account. We have essentially denormalized a bit of Account data for the call and determined that this would occur on the server.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">GraphQL is really an extension of REST, but the key difference is that the resource is decoupled from the way you retrieve it. In GraphQL there is the resource AND then there is the action (the example below uses a Query as the action). Here we define the resource and the action separately where Transaction and Account objects are the resources and the Query type defines basic ways you can retrieve the resources:<br><\/p>\n\n\n\n<pre lang=\"javascript\" line=\"1\">type Transaction {\n id: ID!\n date: Date!\n amount: Float!\n account: Account! \n}\ntype Account {\n id: ID!\n name: String!\n balance: Float!\n transactions: [Transaction!]!\n}\ntype Query {\n  transaction(id: ID!): Transaction\n  account(id: ID!): Account\n}\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\/\/ Note that the exclamation point (!) above represents required &#8211; cannot be null<\/em><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then the GraphQL call in basic URL form is as follows:<br><\/p>\n\n\n\n<pre lang=\"javascript\" line=\"1\">GET \/graphql?query={ transaction(id: \"1234\") { date, amount, account { name } } }\n{\n \"date\": \"2019-05-12\",\n \"amount\": 100.50,\n \"account\": \n {\n   \"name\": \"My Checking\"\n }\n}\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this very simple case above, we are comparing using a GET method for the specific REST call vs. a generic Query method for the GraphQL call. Using the above GraphQL call we can select which fields we want to retrieve from our client application. Therefore, while we are \u201cstuck\u201d with the REST call returning only the name of the Account since that was determined on the server when we implemented the REST call, we have the flexibility of selecting more fields from the Account (e.g., balance) if we prefer when we execute the call from the client without changing any server code. We can expand this example in many facets by adding or subtracting fields and hierarchical objects we are retrieving. Herein lies the major benefit. We no longer need to establish the returning schema on the server knowing that we may need to handle different front-end clients with different requirements for data including fields and levels of data in a hierarchy.<\/p>\n\n\n\n<p>&nbsp;\n<p><strong>Why GraphQL?<\/strong><\/p>\n&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should already see the major benefit of using GraphQL &#8211; its ability to allow the client to define the fields and hierarchies to return without changing the server definition and multiple roundtrips to the server. Those of you who have done many RESTful applications understand that typically you may need three calls to the server before getting the data you need for a single page.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In my examples that follow, I will continue with a fictitious banking application in which there are Customers who have one or more Accounts and those Accounts have zero or more Transactions. Note that an Account can have one or more Customers (think joint account) but a Transaction can only belong to a single Account.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Figure 1.<\/em><br><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"836\" height=\"344\" src=\"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2019\/05\/1-2.png\" alt=\"\" class=\"wp-image-3874\" srcset=\"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2019\/05\/1-2.png 836w, https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2019\/05\/1-2-300x123.png 300w, https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2019\/05\/1-2-768x316.png 768w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Figure 2 shows a mockup of a single web page displaying a Customer\u2019s information along with a list of their Accounts followed by the most recent three Transactions for a selected Account.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Figure 2.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/EL-DUQLfAkOUwFpdoa0hdIYA0QC7BDtNBUSHY01blu6YDXKrwfUkOEHAzWgfDLegh3-iZiqT6E5nx8RXQbobOqsvzr_5HHlpMe2OCTLAH-KzBjUUyk8sWgTcoYDVJUDfND3Bo1kG\" alt=\"\"\/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Using REST we may have situations where we need three or many more calls to the server:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><em> \/customers\/1<\/em> &#8211; retrieve some information from the customer with id of \u201c1\u201d<\/li><li><em> \/customers\/1\/accounts<\/em> &#8211; retrieve that customer\u2019s accounts<\/li><li><em>\/customers\/1\/accounts\/123\/transactions<\/em> &#8211; for each account, retrieve the most recent three transactions<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">In GraphQL there is only one API and that API is controlled by the client so the client can make a single call to retrieve all of the required data including the Customer information, the Accounts, and the most recent three Transactions for each Account. In a traditional REST API environment, how would your REST call be implemented for retrieving the most recent three transactions? Would you have a single REST call to perform all of these three by essentially denormalizing your data and creating a non-REST API? What if you had different client access requiring different sets of data? Developers typically work around this problem by creating more and more REST calls to appease the client and over-fetching data.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The main benefits of GraphQL are:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Hierarchical &#8211; the GraphQL client can request data in a hierarchical form including multiple data items from different parts of a hierarchy with a single call.<\/li><li>Strongly Typed &#8211; since the GraphQL schema is strongly typed, descriptive error messages can be provided with incorrect client calls.<\/li><li>Introspective &#8211; a GraphQL server can be queried for its schema\/API.<\/li><li>No Versioning &#8211; for many traditional RESTful applications, changing the server call to accommodate the client requires a change in the version of the server API and informing the clients. With GraphQL you can add new schema functions without change on the client and you can deprecate other functions but still allow them to function.<\/li><\/ol>\n\n\n\n<div style=\"padding: 12px; background-color: #eee9e9; line-height: 1.2; margin: 40px; border: 1px solid #ccc; border-radius: 6px; box-shadow: 1px #ccc; border-left: 5px solid #61963D;\"><span style=\"font-size: x-large; color: #61963d;\">\u201c<\/span><em>Using GraphQL is a much more dynamic solution to allow client access to data with the freedom to retrieve what is wanted without server changes.<\/em><span style=\"font-size: x-large; color: #61963d; line-height: 1.0;\">\u201d<\/span><\/div>\n\n\n\n<p>&nbsp;\n<p><strong>Tools and Libraries<\/strong><\/p>\n&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are a number of tools and libraries available for GraphQL for all stacks. This includes the Java stack, Ruby on Rails, Python\/Django, and of course JavaScript\/NodeJS. I\u2019ve only tackled GraphQL in the JavaScript\/NodeJS stack so far. <a rel=\"noopener noreferrer\" href=\"https:\/\/www.graphqlstack.com\/\" target=\"_blank\">This website<\/a> that I found provides the clearest view of what libraries exist for each software language at each part of the stack.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With respect to my example banking application I am using a NodeJS server with <a href=\"https:\/\/github.com\/prisma\/graphql-yoga\" target=\"_blank\" rel=\"noopener noreferrer\">graphql-yoga<\/a> library to handle client calls. This package is built upon Express and has a powerful and pleasant web playground to execute actions to the server. In addition, I am using <a href=\"https:\/\/www.prisma.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">Prisma<\/a> as a data layer to provide a pretty expressive ORM that works with SQL and noSQL databases and handles GraphQL calls with simplicity. This ORM autogenerates (no code is generated, but the functions are there) all of the CRUD processing similar to Rails for those of you who have used Rails. It also provides a type-safe client. <br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now when I first was using this architecture I was confused a bit, so let me see if I can explain it simply. In this architecture we can have a web or mobile client executing GraphQL calls which calls to our node server running graphql-yoga which then (by using what\u2019s called resolvers), handles authentication, authorization, and any business functionality and uses our Prisma server for data access &#8211; i.e., we have client-&gt;server-&gt;server. &nbsp;<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since there is much complexity of a graphql function (i.e., so many different possibilities) having an ORM like Prisma is very useful since all of the permutations are handled for you. Any tool like Prisma has its downsides and I will discuss those later.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is our <strong>datamodel.graphql<\/strong> file to define our banking application resources. This file is used by Prisma (our ORM):<br><\/p>\n\n\n\n<pre lang=\"javascript\" line=\"1\">type Customer {\n id: ID! @unique\n firstName: String!\n lastName: String!\n email: String! @unique\n accounts: [Account!]! @relation(name: \"CustomerToAccount\", onDelete: CASCADE)\n}\n\ntype Account {\n id: ID! @unique\n name: String!\n balance: Float!\n owners: [Customer!]! @relation(name: \"CustomerToAccount\", onDelete: CASCADE)\n transactions: [Transaction!]! @relation(name: \"AccountToTransaction\", onDelete: CASCADE)\n}\n\ntype Transaction {\n id: ID! @unique\n date: DateTime!\n amount: Float!\n cleared: Boolean @default(value: \"false\")\n account: Account! @relation(name: \"AccountToTransaction\", onDelete: SET_NULL)\n}\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Again this is defining a Customer with a many-to-many relationship with Accounts and Accounts having a zero-to-many relationship with Transactions. Prisma will generate the database based on the data model above.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here you can see the generated tables in my Postgres database: <br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/nh9_erMLWizOcQy6B3wcK8eji7WV8bShP33KtH5hXFtf_nHMLA3j_xeUeDUt0yDaK2NG1XMBKMtV9h9eRDz-PbiNfq4AMzovV89A-zkXDKnUPuAjlKw8mPX9aO3rYyJGTEbqErS4\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Note that even though one of our relationships is a one-to-many it still generates a cross-reference table.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As mentioned before, GraphQL separates the resource and the actions. Above in our <strong>datamodel.graphql<\/strong> file we defined the resources and in GraphQL we also need to define the actions (i.e., the allowable actions by the client). These actions are defined in a <strong>schema.graphql<\/strong> file as follows for my examples:<br><\/p>\n\n\n\n<pre lang=\"javascript\" line=\"1\">type Mutation {\n createCustomer(data: CustomerCreateInput!): Customer!\n createAccount(data: AccountCreateInput!): Account!\n createTransaction(data: TransactionCreateInput!): Transaction!\n updateCustomer(data: CustomerUpdateInput!, where: CustomerWhereUniqueInput!): Customer\n updateAccount(data: AccountUpdateInput!, where: AccountWhereUniqueInput!): Account\n updateTransaction(data: TransactionUpdateInput!, where: TransactionWhereUniqueInput!): Transaction\n}\n\ninput CustomerCreateInput {\n firstName: String!\n lastName: String!\n email: String!\n accounts: AccountCreateManyWithoutOwnersInput\n}\n\ntype Query {\n customers(where: CustomerWhereInput, orderBy: CustomerOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Customer]!\n accounts(where: AccountWhereInput, orderBy: AccountOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Account]!\n transactions(where: TransactionWhereInput, orderBy: TransactionOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Transaction]!\n customer(where: CustomerWhereUniqueInput!): Customer\n account(where: AccountWhereUniqueInput!): Account\n transaction(where: TransactionWhereUniqueInput!): Transaction\n}\n\ntype Subscription {\n customer(where: CustomerSubscriptionWhereInput): CustomerSubscriptionPayload\n account(where: AccountSubscriptionWhereInput): AccountSubscriptionPayload\n transaction(where: TransactionSubscriptionWhereInput): TransactionSubscriptionPayload\n}\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This file above is generated by Prisma and then altered, imported, or reused in part by the GraphQL yoga server to limit what the client can do. Above we can see queries defined along with mutations and subscriptions. You can ignore some of the complexity of the parameters above within the functions, but understand that this is where you are defining your actions along with the data being fed and returned from those actions. Anywhere there is a resource mentioned (i.e., Account), GraphQL automatically allows you to walk up and down that hierarchy.<\/p>\n\n\n\n<p>&nbsp;\n<p><strong>Setting Up Data for My Examples<\/strong><\/p>\n&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Typically, with many applications we have relationships in our data ranging from simple to complex. To display and explain certain GraphQL statements in the following sections I\u2019m going to use our fictitious bank data model of a Customer having a many-to-many relationship with Accounts (e.g., two people are joint owners on multiple accounts) and a one-to-many relationship between Accounts and Transactions whereas an Account can have zero or more Transactions. <br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Within GraphQL there are three different execution concepts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Query &#8211; retrieve data<\/li><li>Mutation &#8211; create, update, and delete data<\/li><li>Subscription &#8211; publish\/subscribe model to be notified when data changes, typically implemented with <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/WebSockets_API\" target=\"_blank\" rel=\"noopener noreferrer\">WebSockets<\/a> <\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">I have created a simple application using <a href=\"https:\/\/github.com\/prisma\/graphql-yoga\" target=\"_blank\" rel=\"noopener noreferrer\">graphql-yoga<\/a> and <a href=\"https:\/\/www.prisma.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">Prisma<\/a> using the resource and action files above. I did not have to write much code at all. This shows the simplicity out-of-the-box, but more code would be required to deal with things like authentication, authorization, and just plain old business logic on the server. This code is handled within resolvers within the graphql-yoga server.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I have deployed <a rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/afrankel\/solutionstreet-graphql\" target=\"_blank\"><strong>my code<\/strong><\/a> to Heroku and you can get to the running server <a rel=\"noopener noreferrer\" href=\"https:\/\/afternoon-island-18488.herokuapp.com\/\" target=\"_blank\"><strong>using this link<\/strong><\/a><strong>. <\/strong>Since it\u2019s running on Heroku using the free version it may take a minute to start node and Prisma each and then execute its first function. Once you get there you will see the GraphQL Playground where you can follow along with the examples below and implement your queries, mutations, and subscriptions.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The GraphQL Playground (moving forward I\u2019ll just refer to this as playground) looks like the following. <em>Note: The \u201cplay\u201d button in the images does not represent videos. This \u201cplay\u201d button is used by the playground to execute the mutation, query, or subscription.<\/em><br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/1U93GlelNeT4uxYtOU7GhbdpUPqGHNCJ7SYGlDypC0hmWFOv4okWFhwHC5BPz5e-o2FTMyD6pbA6rlV4rPTlBHMUC9o8kg-ZC2y86m0wTpj_HgJNSJG4DeN5b-PI33oCt1G-vYkC\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You can clear the comment line from the left side and type away. You can create your own data and retrieve it. Two important notes when using the playground (or really a GraphQL client) and the default setup with GraphQL\/Prisma:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>When you query any resource\/object you must provide at least one attribute to query. So if you are querying Customers you must ask for at least one attribute. It doesn\u2019t default to every attribute. When you are querying for the Accounts within the Customer you also need to specify at least one attribute to retrieve.<\/li><li>When you are mutating data (create, update, delete) you must return at least one attribute from the resource\/object. If I update Account, I must return some attribute of the object.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You will see this in the examples below. <br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p>&nbsp;\n<p><strong>Create, Update, Delete<\/strong><\/p>\n&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First let me start with Mutations &#8211; Create, Update, and Delete &#8211; since I need to show how the data gets into the database.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using our fictitious banking application I would first need to create some Customers so using the playground we can easily populate the database and validate the functions. Later we will discuss using a JavaScript client (e.g., a React front-end), but the playground is very useful for basic testing of the API. As a side note, the playground can display the schema and documentation from its right side tabs as shown below.<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/Ef4nOTGtVl2sFtHQ9rrEZa77GckT0u-hbqZAGsCNLX8OOoIkRIVnR9E8Mag15sXoY31e2Ql6rOzDvJR1Fylheel-rb_K7Tp5Ih84LaJc-wkvP1Y1ndmBFy7Sp8RfiJaKvrZrKv07\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Below I am just creating two Customers (\u201cArthur\u201d and \u201cJoel\u201d) and can see the resulting id. <br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/_b_TozZmWfcwvYAcPsFX9lyGvStJXQBM783xBg4jB6-jNmYdc6-ZcZSyOsgx59ouGEfs09rW_zzfZCsFqeDQeVcZ4Oe_y5S6_sROQjN3a4poQQcz8WOw1-u_tn82Uq10bmlJXJL6\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/QfgaxzGkOLPpZoM_5HH8duQVLCZqzqkdSateU75ehOousGk36VRFpYj93IilRGt3AHytAYsKN7wpUVbMSr11x_McLfd_sA7kBKgx5AR43W1AI4MKdwBcwLZQtxssC3EUEKebg3ZO\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If we try to execute the last mutation again, we will receive an error due to the \u201c@unique\u201d constraint defined on our email field in our data model for Prisma. <br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/BfyNGiFuTA3pM7OJqfD5PMppywhmxB4RQ-VxtgDEsA4mmSQJzeNHDjdLXAlDOVKrLkw9QD1q9Ah8Xkaqja--VMy06Ra6Klurae9_ymyFE-mESrVud36a84E94Srfz5tDoWXAP0Du\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">There are constraints like \u201c@unique\u201d and others that are handled at the ORM level and then all other control (authentication, authorization, business logic) is handled by the nodeJS server.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now that we have two Customers in the database we can create a new Account and add those Customers to the account. I will do this in two separate functions to show a create then update, but this can be performed with a single call to createAccount.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/KB-lSk9dT2XnVYtvUC2SEgCOo78WBDTJVneqrhIcQbiGM-z4CUcbazT7fZHyn3SYCpu2rFSW0V3MFTnUELLNuBJReTtTbHNzUgJPLgfmdimQj1yI1pzCzKMXmwNVry-RTI4GB0N8\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/mRtjjcrVTDYrd6HMzTv1XrFViNpeIY2g7Enz-AvskuS438jzVgByxvdSiaZUAu-197kJkdrKOP5OwPgdUmVJnr4p2pCsMWmw_EbcKjJsqwf_YJa7x1AtcRFhNJOKv-7fNEXiT2AN\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As a reminder, the data required for \u201cinput\u201d in our functions is required (or not required) based on the schema, but the data returned after the function executes is optional (as we see here with name, balance, and owner info). We always need to return something and if we return a subnode (as in the case of \u201cowners\u201d) we need to have at least one attribute returned.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At this point we have two Customers and one Account with those Customers as owners (i.e., Joint Account) in the database.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now we can add a Transaction to the Account.<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/1joMjtLGydrMhq3dhCp9nL1P5eJr-RukVc0GOAYWUTtfWXqlpu243Ftyfmd0hb3GKWhKlLsMXEYg7D7oIS3VKM-BSWSbHXg8D_ueK-4LurvpTitZXL6i7FsbIvZ4KY_qdUzMDi1e\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here you can see that we added the Transaction with the id of the Account we created previously. <br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At this point in our database we have two Customers, a shared Account with a single Transaction. Each of these functions that I executed above within the playground would typically be executed from a client GraphQL library. Now let\u2019s take a look at how to query the information. &nbsp;Note that I did not show delete functionality since I have limited them in my <strong>schema.graphql<\/strong> file (i.e., they are not in that file so they are not permitted). Depending upon the application, you may want to limit certain functions or not.<\/p>\n\n\n\n<p>&nbsp;\n<p><strong>Query<\/strong><\/p>\n&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First let\u2019s just get a list of our Customers. Here we can see in the playground that we are using our \u201cquery\u201d keyword instead of our \u201cmutation\u201d keyword to start the command.<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/-eNJyIg0V3GF_qY_X91ahNQ2W9mOUc74bPTo8xcVRfYHiyXzu0RZdXWedPDP_PagEQMeTfh_YfUwMfUiFHOIwkFkivJdhdRIU6RaHIWmuOpr2r1TmIWb6m9r_zOWCt0t7GT9aLs3\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here, when we query for an object we can list the attributes we want to be returned (or not be returned).<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the following, we can see how the client can filter the results by searching for a Customer that contains a certain lastName. This example provides a simple filter, but the filters can be complex and also include sorting and pagination.<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/MLOXAJegFMHUVwZoRScH5C3VzSeS9Sa1EKS86_Qc8x1Nocc6505Nnsw_zlYrllTZ2JGBL5aX-fRbfvZJt7np95GncJKTqAbCOcINK7nf6ZMf8yhD3k5KItD2XpxcV114TpYjUhDt\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Of course the powerful aspect of GraphQL is displayed here where we are retrieving a hierarchy of data. We are retrieving all Customers with Customer attributes, all Accounts for those Customers with Account attributes, and all Transactions for those Accounts with Transaction attributes. (Note that in the image we can\u2019t see the full data including the second Customer\u2019s full information.)<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/SQj8sVv3BbDlKYb1ASXT-UvjnNj6_le9RvjH84SCjb2Tce5Y4zCkBLHbUYjM__wPSB_7-hakkHXgqmlBdpiq5JOo9FmRepuNiRd-vumygAn3RXo3Wa1LsIIqcRqVtwyd53BFZZVc\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Given a traditional RESTful server implementation this would typically be three separate calls, but even if it was a single call the specific attributes returned are predefined on the server. In contrast, with GraphQL the client determines the data requested.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Coming back to the original example of requiring the data needed for the mockup in Figure 2, you may have a GraphQL query as follows:<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/HWJNzZkoztL7RqLxbF0mVjbBYo6m9QP7yswYKcuP91oHKfuVuCt3bHE5o3_kAKzbfGr1VYQHRGHz52qN0bNuQYLDBxYuBdLUF73ErK8gf-WNnTcrbsnonjUi65q2xRIndKg2_qWa\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here we are asking for a specific Customer based on the ID and also getting the last three Transactions to display by using the \u201clast\u201d and \u201corderBy\u201d keywords. If the user interface changes or there is a different user interface you can see how you can easily change the query to accommodate the fields on that webpage or mobile device.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;\n<p><strong>Subscriptions<\/strong><\/p>\n&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Another very powerful aspect of GraphQL is Subscriptions. This follows the traditional publish\/subscribe model. We can use Subscriptions in any business application to notify the client when data is added or changed in the database.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here we can define a simple Subscription to notify the client when any modification (create\/update) to a Transaction occurs. When we execute this you notice that the playground is in wait mode and displays \u201cListening\u2026\u201d<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/YVBbDhtc-yFMqnKKS1GP5sZf3ej4TPogfGx1deD_Yz_QO465SoY3YPtZEN55VkhgeFPrynxq2GBABt-xovjZgIdYur03fDBEe0lU-G6nTGzH4X8EKCYmKtifnR-ycRvM869RrBO6\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now once we create a new Transaction\u2026<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/oSf9aZdGw_KnwDEZNkIvmLQDi6NWug3Kk-SKyueQpguULmKz80xci3MQylhMr6AQr7pQNKVUA_v1GZ25M05dlyRLsFfsb84vjAzZez9CpPNy0iwCEWD4AgllhtvfZXF5WCLj1Xxx\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">the original playground tab listening for changes is still listening but notifies the user that a new Transaction was created:<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/qMuXsWkHoQgq5JZwcAMCrQ1dvVOj20n_GbqgdCILILNh69iM58mkDkmOzA2ER_jwYyITRGP1ZtZzpa8crVURKvHRIAHqU_ol4ibpGwrobugeyEPjtb8mKVPN0RDzjmaQ1gqNqjft\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Again within a client library (e.g., React, Angular, Vue) this can be a powerful addition.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At this point we have discussed Mutations, Queries, and Subscriptions and have shown examples using the playground. A traditional application would have a client front-end (web or mobile) and use something like a GraphQL client such as <a href=\"https:\/\/www.apollographql.com\/docs\/react\/\" target=\"_blank\" rel=\"noopener noreferrer\">Apollo<\/a> and integrate this library within something like a React\/Angular\/Vue front-end. <br><\/p>\n\n\n\n<p>&nbsp;\n<p><strong>N+1<\/strong><\/p>\n&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When I first started looking into GraphQL I was immediately thinking about the <a href=\"https:\/\/stackoverflow.com\/questions\/97197\/what-is-the-n1-selects-problem-in-orm-object-relational-mapping\" target=\"_blank\" rel=\"noopener noreferrer\">N+1 problem<\/a> &#8211; where you may be performing exponentially more queries needed for each sub or parent node. Using our banking application example, fetching the Accounts and getting the owners of each Account (i.e., Customer objects) may require many queries. Getting the Accounts may be one SQL statement, but then there is a request for a Customer(s) associated with every Account. This could easily lead to another request for every Account (i.e., N+1). With ORMs like Prisma, this is a concern, but really even if you were hand-rolling an ORM, this would always be a concern. <br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With REST this is certainly a problem but you can predict the call since the server REST call is static. With GraphQL the N+1 problem is further exacerbated because the server cannot predict how expensive the request will be before it\u2019s executed. The solution to this is the <a href=\"https:\/\/github.com\/graphql\/dataloader\" target=\"_blank\" rel=\"noopener noreferrer\">dataloader<\/a> library. You can implement solutions for dataloader within your resolvers when you come across problems. Dataloader is part of Prisma and therefore (it allegedly) is safer from the N+1 problem. In Prisma there is a logging level that allows you to dump the SQL statements to monitor the number of SQL statements executed.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As with any ORM you need to be careful of these situations and I am just pointing out that this problem is broader with a GraphQL server API.<br><\/p>\n\n\n\n<p>&nbsp;\n<p><strong>GraphQL Client<\/strong><\/p>\n&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using GraphQL on the client comes in many forms\/libraries, but I wanted to provide a very simple example to show how a query is executed on the client. <br><\/p>\n\n\n\n<pre lang=\"javascript\" line=\"1\">import ApolloBoost, { gql } from 'apollo-boost'\n\nconst client = new ApolloBoost({\n   \/\/ pointing to my GraphQL server on heroku\n   uri: 'https:\/\/afternoon-island-18488.herokuapp.com\/' \n})\n\n\/\/ same type of query we see in the GraphQL Playground\nconst getCustomers = gql`\n   query {\n       customers {\n           firstName\n           lastName\n       }\n   }`\n\nclient.query({\n   query: getCustomers\n}).then((response) =&gt; {\n   let html = ''\n   response.data.customers.forEach((customer) =&gt; {\n       html += `\n           <div>\n               <h3>${customer.firstName} ${customer.lastName}<\/h3>\n           <\/div>\n       `\n   })\n\n   document.getElementById('customers').innerHTML = html\n})\n\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019m using <a rel=\"noopener noreferrer\" href=\"https:\/\/www.apollographql.com\/docs\/react\/essentials\/get-started\" target=\"_blank\">Apollo Boost<\/a> (barebones &#8211; typically you would use extra libraries for integration with React or similar front-end frameworks). <a rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/afrankel\/solutionstreet-graphql-client\" target=\"_blank\"><strong>Here is my code<\/strong><\/a> on GitHub which you can clone, install, and execute. <\/p>\n\n\n\n&nbsp;\n<p><strong>So Why Aren&#8217;t We All Using GraphQL?<\/strong><\/p>\n&nbsp;\n\n\n\n<p class=\"wp-block-paragraph\">When I first started looking into GraphQL I was very impressed. It\u2019s pretty easy to see how it solves an important issue of replacing static REST calls dictated by UI changes with a very dynamic hierarchical data retrieval. I also could see the benefit of using GraphQL as an API engine to deal with an issue we have here at Solution Street &#8211; lots of applications require custom reporting to handle all sorts of data requests. Using GraphQL is a much more dynamic solution to allow client access to data with the freedom to retrieve what is wanted without server changes.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you look at the history of API development, not too long before REST and GraphQL was Web Services&#8230;and yes, they are still used today. With the SOAP protocol and using XML, Web Service APIs are defined and called in a verbose way as defined by the server. The benefit with Web Services is the detail-oriented aspect of the API and the server flexibility of the API. REST became the de facto choice after Web Services because of its simplicity and convention. Any developer could join a new project and immediately understand the APIs. Unfortunately many developers go outside of the convention of REST and create APIs that cater to the User Interface and muddy the waters. GraphQL may not have the simple convention that REST does, but it provides a dynamic, flexible interface that has the ability to be directed by the client (User Interface) unlike REST and Web Services.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With all of the positive aspects, I have run into several items which I believe are at the core of why we aren&#8217;t using GraphQL. <\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>It\u2019s harder to implement even with using Prisma as an ORM. Although Prisma gives you a whole lot without any code, in a real-world situation there is a lot more to do. If you want to actually implement authentication and authorization as part of the CRUD calls you can implement your needs and then call \u201cup\u201d to Prisma, but <a href=\"https:\/\/github.com\/graphql-binding\/graphql-binding\/issues\/40\" target=\"_blank\" rel=\"noopener noreferrer\">it\u2019s still not that easy<\/a>. If you are not using an ORM like Prisma, implementing all of the database calls within every resolver and handling every aspect of the hierarchy is certainly more difficult than standard REST.<\/li><li>It\u2019s confusing to figure out what you need. As mentioned, <a href=\"https:\/\/www.graphqlstack.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">this website<\/a> helps you identify the pieces, but even on this website it\u2019s confusing to know what you need and where it fits in your architecture.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Like all technology, this is evolving and will hopefully be simpler. Even with these items above, I would use GraphQL to create an enterprise application with multiple client types (web, mobile, API). I like that it solves a problem and with the ever-changing aspects of user interfaces, having a dynamic server API is very powerful.<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Origin of GraphQL &nbsp; Back in 2012, Facebook was dealing with an issue that many of us software developers who build products with multiple front-ends (web and mobile) must address. How can we build a server component Application Programming Interface (API) that works seamlessly with both mobile and web applications? How can we have the [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3852","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>You Really Should Be Using GraphQL - Solution Street Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"You Really Should Be Using GraphQL - Solution Street Blog\" \/>\n<meta property=\"og:description\" content=\"Origin of GraphQL &nbsp; Back in 2012, Facebook was dealing with an issue that many of us software developers who build products with multiple front-ends (web and mobile) must address. How can we build a server component Application Programming Interface (API) that works seamlessly with both mobile and web applications? How can we have the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/\" \/>\n<meta property=\"og:site_name\" content=\"Solution Street Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-29T01:14:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2019\/05\/rowingguy3title3.png\" \/>\n<meta name=\"author\" content=\"Peggy Frankel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Peggy Frankel\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"21 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2019\\\/05\\\/29\\\/you-really-should-be-using-graphql\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2019\\\/05\\\/29\\\/you-really-should-be-using-graphql\\\/\"},\"author\":{\"name\":\"Peggy Frankel\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/#\\\/schema\\\/person\\\/c4846451eff30e9514b534b2a2e01696\"},\"headline\":\"You Really Should Be Using GraphQL\",\"datePublished\":\"2019-05-29T01:14:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2019\\\/05\\\/29\\\/you-really-should-be-using-graphql\\\/\"},\"wordCount\":3658,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2019\\\/05\\\/29\\\/you-really-should-be-using-graphql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/rowingguy3title3.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2019\\\/05\\\/29\\\/you-really-should-be-using-graphql\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2019\\\/05\\\/29\\\/you-really-should-be-using-graphql\\\/\",\"url\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2019\\\/05\\\/29\\\/you-really-should-be-using-graphql\\\/\",\"name\":\"You Really Should Be Using GraphQL - Solution Street Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2019\\\/05\\\/29\\\/you-really-should-be-using-graphql\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2019\\\/05\\\/29\\\/you-really-should-be-using-graphql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/rowingguy3title3.png\",\"datePublished\":\"2019-05-29T01:14:56+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/#\\\/schema\\\/person\\\/c4846451eff30e9514b534b2a2e01696\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2019\\\/05\\\/29\\\/you-really-should-be-using-graphql\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2019\\\/05\\\/29\\\/you-really-should-be-using-graphql\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2019\\\/05\\\/29\\\/you-really-should-be-using-graphql\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/rowingguy3title3.png\",\"contentUrl\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/rowingguy3title3.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2019\\\/05\\\/29\\\/you-really-should-be-using-graphql\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"You Really Should Be Using GraphQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/\",\"name\":\"Solution Street Blog\",\"description\":\"Quality Software Engineering - Technology and Consulting Articles\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/#\\\/schema\\\/person\\\/c4846451eff30e9514b534b2a2e01696\",\"name\":\"Peggy Frankel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/af71ceb16f89d32c9bb825a47f8057da9283b4a27a934bf0c47cdef65ad0eb5d?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/af71ceb16f89d32c9bb825a47f8057da9283b4a27a934bf0c47cdef65ad0eb5d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/af71ceb16f89d32c9bb825a47f8057da9283b4a27a934bf0c47cdef65ad0eb5d?s=96&d=mm&r=g\",\"caption\":\"Peggy Frankel\"},\"url\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/author\\\/pfrankel\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"You Really Should Be Using GraphQL - Solution Street Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/","og_locale":"en_US","og_type":"article","og_title":"You Really Should Be Using GraphQL - Solution Street Blog","og_description":"Origin of GraphQL &nbsp; Back in 2012, Facebook was dealing with an issue that many of us software developers who build products with multiple front-ends (web and mobile) must address. How can we build a server component Application Programming Interface (API) that works seamlessly with both mobile and web applications? How can we have the [&hellip;]","og_url":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/","og_site_name":"Solution Street Blog","article_published_time":"2019-05-29T01:14:56+00:00","og_image":[{"url":"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2019\/05\/rowingguy3title3.png","type":"","width":"","height":""}],"author":"Peggy Frankel","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Peggy Frankel","Est. reading time":"21 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/#article","isPartOf":{"@id":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/"},"author":{"name":"Peggy Frankel","@id":"https:\/\/www.solutionstreet.com\/blog\/#\/schema\/person\/c4846451eff30e9514b534b2a2e01696"},"headline":"You Really Should Be Using GraphQL","datePublished":"2019-05-29T01:14:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/"},"wordCount":3658,"commentCount":0,"image":{"@id":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2019\/05\/rowingguy3title3.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/","url":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/","name":"You Really Should Be Using GraphQL - Solution Street Blog","isPartOf":{"@id":"https:\/\/www.solutionstreet.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/#primaryimage"},"image":{"@id":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2019\/05\/rowingguy3title3.png","datePublished":"2019-05-29T01:14:56+00:00","author":{"@id":"https:\/\/www.solutionstreet.com\/blog\/#\/schema\/person\/c4846451eff30e9514b534b2a2e01696"},"breadcrumb":{"@id":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/#primaryimage","url":"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2019\/05\/rowingguy3title3.png","contentUrl":"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2019\/05\/rowingguy3title3.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.solutionstreet.com\/blog\/2019\/05\/29\/you-really-should-be-using-graphql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.solutionstreet.com\/blog\/"},{"@type":"ListItem","position":2,"name":"You Really Should Be Using GraphQL"}]},{"@type":"WebSite","@id":"https:\/\/www.solutionstreet.com\/blog\/#website","url":"https:\/\/www.solutionstreet.com\/blog\/","name":"Solution Street Blog","description":"Quality Software Engineering - Technology and Consulting Articles","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.solutionstreet.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.solutionstreet.com\/blog\/#\/schema\/person\/c4846451eff30e9514b534b2a2e01696","name":"Peggy Frankel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/af71ceb16f89d32c9bb825a47f8057da9283b4a27a934bf0c47cdef65ad0eb5d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/af71ceb16f89d32c9bb825a47f8057da9283b4a27a934bf0c47cdef65ad0eb5d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/af71ceb16f89d32c9bb825a47f8057da9283b4a27a934bf0c47cdef65ad0eb5d?s=96&d=mm&r=g","caption":"Peggy Frankel"},"url":"https:\/\/www.solutionstreet.com\/blog\/author\/pfrankel\/"}]}},"_links":{"self":[{"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/posts\/3852","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/comments?post=3852"}],"version-history":[{"count":0,"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/posts\/3852\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/media?parent=3852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/categories?post=3852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/tags?post=3852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}