Let's Build A Graph

Joe Fleming

  • Software Engineer @ Sibi
  • WebDev for over a decade
  • Using GraphQL for ~3 months

@w33ble

Overview

  • What is GraphQL?
  • Cover Schema Definition Language (SDL)
  • Build a GraphQL Server with Apollo
  • Resolvers and Field Resolvers

Not Covered

  • "Advanced" GraphQL Concepts
    • Scalars
    • Directives
  • Authentication or Authorization
  • Caching & DDoS Prevention
  • Relay
  • TypeScript types generation

Graph, noun

The collection of all points whose coordinates satisfy a given relation (such as a function)

GraphQL

An open-source data query and manipulation language for APIs, and a runtime for fulfilling queries with existing data

https://www.merriam-webster.com/dictionary/graph

export default function talk() {
  return {
    title: "Let's Build a Graph",
    presenters: [{
      name: "Joe Fleming",
      alias: "w33ble"
    }],
  };
}
type Talk {
  title: String!
  presenters: [Presenter]!
}
  
type Presenter {
  name: String!
  alias: String
}

type Query {
  talk: Talk!
}
export default function talk() {
  return {
    title: "Let's Build a Graph",
    presenters: [{
      name: "Joe Fleming",
      alias: "w33ble"
    }],
  };
}
export default {
  Query: {
    talk() {
      return {
        title: "Let's Build a Graph",
        presenters: [{
            name: "Joe Fleming",
            alias: "w33ble"
        }],
      };
    }
  },
};

Mutations

Used to add, update, and delete data from your API. Equivalent to a PUT, POST, and DELETE requests in REST.

Queries

Reading data from your GraphQL API. Equivalent to a GET request in REST, used for reading data.

Always uses POST

It doesn't matter if you are querying or mutating data, all requests are POST requests

Your entire graph is accessible through a single endpoint, usually /graphql

Single Endpoint

{
  talk {
    title
    presenters {
      name
      alias
    }
  }
}
$ curl -XPOST \
  --url http://localhost:4000/graphql \
  -d '{"query":"{ talk { title, presenters { name, alias } } }"}'

Resources

Resources

Let's Build a Graph

By Joe Fleming

Let's Build a Graph

  • 1,041