Saturday, May 25, 2019

I saw Cory House speak on GraphQL at the Norwegian Developers Conference.

What if the client has more power, not just the server? That is the premise of GraphQL. Cory House recommended using GraphiQL as a tool to interact with a GraphQL endpoint. At the left pane you'll form a query in something like a JSON form shaped like so:

query {
   allPosts {
      id
      title
      views
   }
}

 
 

As best as I can tell this is the destructuring JavaScript syntax used for pulling pieces out of a bigger JSON object like so:

const { first, last } = person;

 
 

If title becomes myTitle: title in our query above it renames a property in sucking it over. JSON GraphQL Server is kind of like JSON Server. You may wire up a graph to query against. All interactions with GraphQL are done with the POST verb which tends to invalidate caching. A resolver is a function that returns a specific thing from elsewhere in the midst of the server side of GraphQL. If a graph is aggregated from three other web services you have to reach out to those web services at some point, right? The calls out are called resolvers in this space. A good way to get started in this space in transitioning from ReST is to wrap existing API calls and then get back pieces of your data. You may parameterize a query. One of the problems with OData was that it was open by default. With GraphQL you start out completely closed. I, the UI developer, decide which queries get passed in, disallowing a SELECT * scenario, hopefully. Be careful of overfetching in which you wanted a banana and you grabbed the whole jungle. You may make a graph from a PostgreSQL database. Akamai is a tool for GraphQL data caching. What do you want to do with file data? Store the files as blobs? No. Have links to files in your graph. GraphQL is being thought of as the backend for the frontend. A schema may have a query inside of it like the one at the top of this blog post and it also may contain a mutation like so:

mutation {
   createPost(id: 1, title: "I love GraphQL", views: 100, user_id: 254)
}

 
 

At the end of the talk Cory House asserted that while GraphQL is an actual specification, that ReST never was. It came from Roy Fielding giving a dissertation and everyone ran with their own implementations of it. The HatEoAS Hypermedia stuff is hardly used, but it is cornerstone to the original idea which has arguably decayed as it has "evolved" over time.

No comments:

Post a Comment