⚡️Lightning Talk

by Carlos Contreras

 me

1. Dismissal

One more JavaScript library?! Just use jQuery already!

2. Interest

Hmm, maybe I should check out this new library I keep hearing about…

3. Panic

Help! I need to learn this new library right now or I’ll be completely obsolete!

The three stages when hearing about a new technology:

GraphQL Fundamentals

What is GraphQL?

GraphQL is a syntax* that describes how to ask for data that provides a more efficient, powerful and flexible alternative to REST. 

mongoDB

PostreSQL

Memcache

 

The client asks for various data from the GraphQL server via queries. The response format is described in the query and defined by the client instead of the server: they are called client‐specified queries.
 

{
  github {
    user(username: "DarthCharles") {
      login
      id
      avatar_url
      repos {
        name
      }
    }
  }
}

Data Fetching with REST vs GraphQL

 

GraphQL is two parts

Query language

Runtime

 We can use the language to communicate queries for reading actions and mutations for writing actions.

 

A GraphQL operation can have:

  • Fields
  • Arguments
  • Variables
  • Directives
  • Aliases
  • Fragments
  • Mutations

  We write GraphQL operations in "documents" on the client-side, and then use an interface to send these documents to a GraphQL server.

 

 HTTP is a popular option but it's not the only one we can use, for example, use Sockets, or an SSH protocol, or a simple command-line interface that works with an executable binary.

Relay

The runtime's job is to understand GraphQL documents and translate them for the other services in the server-side stack.

The data services layers will prepare the data for the request and hand it to the GraphQL engine, which puts it together and sends it to the client who asked for it.

Before starting to build your server, GraphQL requires you to design a schema which in turn defines the API of your server.

A GraphQL schema must have:

  •  Types which expose objects in your application
  •  Fields which expose properties of those objects (and may connect types to other types)
  •  Query root, which is a special type used for executing read queries
  •  Mutation root, which is a special type used for executing mutations
{
  getAuthor(id: 5){
    name
    posts {
      title
      author {
        name
      }
    }
  }
}
{
  data: {
    getAuthor: {
      name: "Carlos Contreras",
      posts: [
        {
          title: "Hello World",
          author: {
            name: "Carlos Contreras"
          }
        },{
          title: "Why am I still up at midnight writing this talk on my birthday 🎈?",
          author: {
            name: "Carlos Contreras"
          }
        }
      ]
    }
  }
}

Questions? 🤔

Thank you!

GrapQL - Lightning Talk

By Carlos Contreiras

GrapQL - Lightning Talk

  • 321