Effortless GraphQL with Transactional NoSQL · 2019-09-19 · Confidential © Fauna, Inc. 2019...

Preview:

Citation preview

Confidential © Fauna, Inc. 2019

Effortless GraphQL

with Transactional

NoSQL

Confidential © Fauna, Inc. 2019

Founded in 2012 by the team that scaled Twitter’s infrastructure

$25M Series A, largest ever by an OLTP database company

Headquartered in Boston, MA and San Francisco, CA

FaunaDB : A cloud-first operational database for enterprises

Fauna: Overview

2

Our Angels

Kevin Scott

CTO, Microsoft

Olivier Pomel

CEO, Datadog

Mazen Al-Rawashdeh

VP, eBay

Larry Gadea

CEO, Envoy Our Investors

Confidential © Fauna, Inc. 2019

Agenda

• What is GraphQL?

• What is FaunaDB?

• The GraphQL Ecosystem

• Get Started (So Easy!)

• FaunaDB’s GraphQL API

Confidential © Fauna, Inc. 2019 4

• Unified API

• Decouples Backend and Frontend

• Specify the shape of data you want on the

front end, and let the backend decide how to

get it

• GraphQL engine handles composing queries

and data

What is GraphQL?

Confidential © Fauna, Inc. 2019

• One request, any data

• One endpoint

• Opinionated– in a good way

• Self documenting

• Pairs well with FaunaDB

Why GraphQL

5

Confidential © Fauna, Inc. 2019

• Serverless & globally distributed

• Relational NoSQL

• ACID transactions

• Temporal data retention

• Security / RBAC

• SaaS multi-tenancy

Why FaunaDB

6

Confidential © Fauna, Inc. 2019

GraphQL Ecosystem

7

Confidential © Fauna, Inc. 2019

GraphQL Stack

8

Confidential © Fauna, Inc. 2019

GraphQL, Simplified

9

Confidential © Fauna, Inc. 2019

FaunaDB GraphQL API

10

https://fauna.com/blog/getting-started-with-graphql-part-1-importing-and-querying-your-

schema

Confidential © Fauna, Inc. 2019

type Todo {

title: String!

completed: Boolean!

list: List

}

type List {

title: String!

todos: [Todo] @relation

}

type Query {

allTodos: [Todo!]

todosByCompletedFlag(completed: Boolean!): [Todo!]

allLists: [List!]

}

Import a Schema

11

Confidential © Fauna, Inc. 2019

input ListTodosRelation {

create: [TodoInput]

connect: [ID]

disconnect: [ID]

}

input TodoInput {

title: String!

completed: Boolean!

list: TodoListRelation

}

See the Generated Schema

12

Confidential © Fauna, Inc. 2019

FaunaDB Schema Elements

13

• The Generated FaunaDB schema can be queried via FQL or GraphQL

• CQL, SQL coming soon

Confidential © Fauna, Inc. 2019

Create Documents

14

mutation CreateAListWithTodos {

createList(data: {

title: "The Basics",

todos: { create: [

{completed: false, title: "Water"},

{completed: false, title: "Food"},

{completed: false, title: "Shelter"}]},

}) {

title

_id

todos {

data {

title

}

}

}

}

Confidential © Fauna, Inc. 2019

Query a List with Todos

15

query FindAListByID {

findListByID(id: "235692310689481217") {

title

todos {

data {

title

completed

_id

}

}

}

}

Confidential © Fauna, Inc. 2019

Mark a Todo as Completed

16

mutation UpdateATodo {

updateTodo(id: "235692310694724097", data: {

title: "Build an awesome app!"

completed: true

}) {

title

completed

}

}

Confidential © Fauna, Inc. 2019

Query for Completed Todos

17

query FindAllCompletedTodos {

todosByCompletedFlag(completed: true) {

data {

title

}

}

}

Confidential © Fauna, Inc. 2019

Query for Completed Todos (FQL)

18

Map(Paginate(

Match(

Index("todosByCompletedFlag"), true)),

(todo) => Get(todo))

Confidential © Fauna, Inc. 2019

clearDone(id: ID!): [Todo!] @resolver(name: "clear_done")

CreateFunction({

name: "clear_done",

body: Query(Lambda(["list_id"],

Map(Paginate(Match(Index("list_todos_by_list"), Var("list_id"))),

(todoRef) => Let({ todo : Get(todoRef)},

If(Select(["data", "completed"], Var("todo")),

Delete(todoRef),

Var("todo")

)))

))

})

Let’s Get Transactional

19

Confidential © Fauna, Inc. 2019

Next Steps

FaunaDB Cloud

• GraphQL tutorial:

https://docs.fauna.com/fauna/current/graphql

• Free database signup: https://fauna.com

Confidential © Fauna, Inc. 2019

Thank You

Recommended