Fundamental Propertjes of the GraphQL Language Olaf Hartjg - - PowerPoint PPT Presentation

fundamental propertjes of the graphql language
SMART_READER_LITE
LIVE PREVIEW

Fundamental Propertjes of the GraphQL Language Olaf Hartjg - - PowerPoint PPT Presentation

Fundamental Propertjes of the GraphQL Language Olaf Hartjg @olafiartjg Joint work with Jorge Prez from the Universidad de Chile Olaf Hartjg Fundamental Propertjes of the GraphQL Language 2 Olaf Hartjg Fundamental Propertjes of the


slide-1
SLIDE 1

Fundamental Propertjes of the GraphQL Language

Olaf Hartjg

@olafiartjg

Joint work with Jorge Pérez from the Universidad de Chile

slide-2
SLIDE 2

2 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

slide-3
SLIDE 3

3 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

slide-4
SLIDE 4

4 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Why study the GraphQL language formally?

Highlight intrinsic limitations

  • f all possible implementations

Identify optimization opportunities Clarify possible corner cases

slide-5
SLIDE 5

5 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Our Results in a Nutshell

Formal definition of the language Study of computational complexity (the language admits really efficient evaluation methods) Solution to the problem of large results

slide-6
SLIDE 6

Formalizatjon of GraphQL

slide-7
SLIDE 7

7 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Why?

slide-8
SLIDE 8

8 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Why?

slide-9
SLIDE 9

9 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Why?

slide-10
SLIDE 10

10 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

GraphQL Graphs (Our Formalizatjon)

slide-11
SLIDE 11

11 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

GraphQL Graphs (Our Formalizatjon)

Typed nodes

slide-12
SLIDE 12

12 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

GraphQL Graphs (Our Formalizatjon)

Typed nodes One special node

slide-13
SLIDE 13

13 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

GraphQL Graphs (Our Formalizatjon)

Typed nodes One special node Node properties

slide-14
SLIDE 14

14 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

GraphQL Graphs (Our Formalizatjon)

Typed nodes One special node Node properties Edge properties

slide-15
SLIDE 15

15 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

GraphQL Graphs (Our Formalizatjon)

Typed nodes One special node Node properties Edge properties

We also formalize the notions of GraphQL schema and schema satisfaction based on this data model

slide-16
SLIDE 16

16 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Formalizatjon of Query Evaluatjon Functjon

slide-17
SLIDE 17

17 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Formalizatjon of Query Evaluatjon Functjon

friends { name }⟧

u

=

slide-18
SLIDE 18

18 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Formalizatjon of Query Evaluatjon Functjon

= friends: [ ]

friends { name }⟧

u

slide-19
SLIDE 19

19 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Formalizatjon of Query Evaluatjon Functjon

friends: [ { ⟦ name⟧

v} { ⟦

name⟧

w} ]

=

friends { name }⟧

u

slide-20
SLIDE 20

20 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Formalizatjon of Query Evaluatjon Functjon

= friends: [ {name:R2-D2} {name:Han} ]

friends { name }⟧

u

slide-21
SLIDE 21

21 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Formalizatjon of Query Evaluatjon Functjon

⟧ hero[episode:EMPIRE] { friends {name} }

slide-22
SLIDE 22

22 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Formalizatjon of Query Evaluatjon Functjon

r

hero[episode:EMPIRE] { friends {name} }

slide-23
SLIDE 23

23 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Formalizatjon of Query Evaluatjon Functjon

r

hero[episode:EMPIRE] { friends {name} }

= hero: { ⟦ friends {name} ⟧

u }

slide-24
SLIDE 24

24 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Formalizatjon of Query Evaluatjon Functjon

r

hero[episode:EMPIRE] { friends {name} }

= hero: { ⟦ friends {name} ⟧

u }

= hero: { friends: [ {name:R2-D2} {name:Han} ] }

slide-25
SLIDE 25

Complexity Analysis

Evaluation Problem

slide-26
SLIDE 26

26 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Evaluatjon Problem of GraphQL

GraphQL query q GraphQL graph G data value d yes no Does d occur in the result of q over G? Does d occur in the result of q over G?

slide-27
SLIDE 27

27 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Complexity Classes

PSPACE NP P

slide-28
SLIDE 28

28 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Complexity of Evaluatjon Problems

PSPACE NP P Relational Algebra SPARQL Conjunctive Queries BGPs (SPARQL)

slide-29
SLIDE 29

29 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Complexity of Evaluatjon Problems

PSPACE NP P NL GraphQL Relational Algebra SPARQL Conjunctive Queries BGPs (SPARQL)

slide-30
SLIDE 30

Complexity Analysis

Enumeration Problem

slide-31
SLIDE 31

31 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Non-Redundancy

hero { name: Luke friends: [ { name: R2-D2} { name: Han} ] id: 1000 name: Luke friends: [ { id: 2001} { id: 1002} ] } hero[episode: EMPIRE] { name friends { name } id name friends { id } }

Valid query Invalid result

slide-32
SLIDE 32

32 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Non-Redundancy

hero[episode: EMPIRE] { name friends { name } id name friends { id } }

Valid query

hero { name: Luke friends: [ { name: R2-D2 Id: 2001 } { name: Han Id: 1002 } ] id: 1000 }

Fields are collected before answering Correct result

slide-33
SLIDE 33

33 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Non-Redundancy

hero { name: Luke friends: [ { name: R2-D2 Id: 2001 } { name: Han Id: 1002 } ] id: 1000 } hero[episode: EMPIRE] { name friends { name id } id }

Fields are collected before answering Non-redundant query Correct result

slide-34
SLIDE 34

34 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Another Complicatjon: Type Restrictjons

hero[episode: EMPIRE] { name friends {

  • n Droid { name }
  • n Human { id }

name } }

Valid query Invalid result

hero { name: Luke friends: [ { name: R2-D2 name: R2-D2 } { id: 1002 name: Han } ] }

slide-35
SLIDE 35

35 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Another Complicatjon: Type Restrictjons

hero[episode: EMPIRE] { name friends {

  • n Droid { name }
  • n Human { id }

name } }

Valid query Correct result

hero { name: Luke friends: [ { name: R2-D2 } { id: 1002 name: Han } ] }

slide-36
SLIDE 36

36 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Another Complicatjon: Type Restrictjons

hero[episode: EMPIRE] { name friends {

  • n Droid { name }
  • n Human { id name }

} }

Valid query Correct result

hero { name: Luke friends: [ { name: R2-D2 } { id: 1002 name: Han } ] }

slide-37
SLIDE 37

37 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Ground-Typed Normal Form

hero[episode: EMPIRE] { name friends {

  • n Droid { name }
  • n Human { id name }

} }

Ground-typed query Correct result

hero { name: Luke friends: [ { name: R2-D2 } { id: 1002 name: Han } ] }

slide-38
SLIDE 38

38 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Eliminatjng Redundancies

Rewriting rules for queries Every GraphQL query q can be rewritten into a query q’ that is i) non-redundant and ii) in ground-typed normal form, such that q ≡ q’ Advantage: field collection is not needed for non-redundant queries in ground-typed NF

slide-39
SLIDE 39

39 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Now to the Enumeratjon Problem

Let q be i) non-redundant and ii) in ground-typed normal form Result of q can be produced symbol by symbol with only constant time between symbols Time to produce the complete query result depends linearly on the size of this result

hero { friends: [ { name:R2-D2} ] }

slide-40
SLIDE 40

Complexity Analysis

Result Size

slide-41
SLIDE 41

41 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Results of GraphQL queries can be huge

start { knows { knows { … { knows { name } }… } } } Alice appears 2N times in the result

2N times

slide-42
SLIDE 42

42 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Huge results in practjce: Github’s GraphQL API

Owners of first five repos that user “danbri” contributes to, and the owners of first five repos that they contribute to, and so on...

slide-43
SLIDE 43

43 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Result sizes can be computed effjciently!!!

Let q be i) non-redundant and ii) in ground-typed normal form Time to compute the size of the result

  • f q over a graph G depends linearly on

the product (size of q) × (size of G)

slide-44
SLIDE 44

44 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Result-Size Computatjon

start { advisor { univ { name } } friend { univ { name } } }

size(q, r) = 4 + size(q2 ,u) + size(q3 ,u) q2 q3

start: { … … } Result:

slide-45
SLIDE 45

45 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Result-Size Computatjon

start { advisor { univ { name } } friend { univ { name } } }

size(q, r) = 4 + size(q2 ,u) + size(q3 ,u) size(q2 ,u) = size(q3 ,u) = q3 q2

slide-46
SLIDE 46

46 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Result-Size Computatjon

start { advisor { univ { name } } friend { univ { name } } }

size(q, r) = 4 + size(q2 ,u) + size(q3 ,u) q3 size(q2 ,u) = 4 + size(q4 ,v) size(q3 ,u) = q4 q2

slide-47
SLIDE 47

47 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Result-Size Computatjon

start { advisor { univ { name } } friend { univ { name } } }

size(q, r) = 4 + size(q2 ,u) + size(q3 ,u) q3 size(q2 ,u) = 4 + size(q4 ,v) size(q3 ,u) = q5 size(q4 ,v) = 4 + size(q5 ,w) q4 q2

slide-48
SLIDE 48

48 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Result-Size Computatjon

start { advisor { univ { name } } friend { univ { name } } }

size(q, r) = 4 + size(q2 ,u) + size(q3 ,u) q3 size(q2 ,u) = 4 + size(q4 ,v) size(q3 ,u) = q5 size(q4 ,v) = 4 + size(q5 ,w) q4 size(q5 ,w) = 3 size(q5) = 3 q2

slide-49
SLIDE 49

49 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Result-Size Computatjon

start { advisor { univ { name } } friend { univ { name } } }

size(q, r) = 4 + size(q2 ,u) + size(q3 ,u) q3 size(q2 ,u) = 4 + size(q4 ,v) size(q3 ,u) = q5 size(q4 ,v) = 4 + size(q5 ,w) = 4 + 3 = 7 q4 size(q5 ,w) = 3 size(q4) = 7 size(q5) = 3 q2

slide-50
SLIDE 50

50 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Result-Size Computatjon

start { advisor { univ { name } } friend { univ { name } } }

size(q, r) = 4 + size(q2 ,u) + size(q3 ,u) q3 size(q2 ,u) = 4 + size(q4 ,v) = 11 size(q3 ,u) = q5 size(q4 ,v) = 4 + size(q5 ,w) = 4 + 3 = 7 q4 size(q5 ,w) = 3 size(q4) = 7 size(q5) = 3 size(q2) = 11 q2

slide-51
SLIDE 51

51 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Result-Size Computatjon

start { advisor { univ { name } } friend { univ { name } } }

size(q, r) = 4 + size(q2 ,u) + size(q3 ,u) q3 size(q2 ,u) = 4 + size(q4 ,v) = 11 size(q3 ,u)= 4 + size(q4 ,v) q5 size(q4 ,v) = 4 + size(q5 ,w) = 4 + 3 = 7 q4 size(q5 ,w) = 3 size(q4) = 7 size(q5) = 3 size(q2) = 11 q4 q2

slide-52
SLIDE 52

52 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Result-Size Computatjon

start { advisor { univ { name } } friend { univ { name } } }

size(q, r) = 4 + size(q2 ,u) + size(q3 ,u) q3 size(q2 ,u) = 4 + size(q4 ,v) = 11 size(q3 ,u)= 4 + size(q4 ,v) = 4 + 7 = 11 q5 size(q4 ,v) = 4 + size(q5 ,w) = 4 + 3 = 7 q4 size(q5 ,w) = 3 size(q4) = 7 size(q5) = 3 q4 size(q2) = 11 size(q3) = 11 q2

slide-53
SLIDE 53

53 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Result-Size Computatjon

start { advisor { univ { name } } friend { univ { name } } }

size(q, r) = 4 + size(q2 ,u) + size(q3 ,u) = 26 q3 size(q2 ,u) = 4 + size(q4 ,v) = 11 size(q3 ,u)= 4 + size(q4 ,v) = 4 + 7 = 11 q5 size(q4 ,v) = 4 + size(q5 ,w) = 4 + 3 = 7 q4 size(q5 ,w) = 3 size(q4) = 7 size(q5) = 3 size(q2) = 11 size(q3) = 11 q4 q2 11 11

slide-54
SLIDE 54

54 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Proposal for GraphQL Servers

First, compute the size of the result. If too big, reject query. Else, inform the size to the client, and Send the result byte by byte. (or use the size as basis of a billing model)

slide-55
SLIDE 55

Summary

slide-56
SLIDE 56

56 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language

Our Results in a Nutshell

Formal definition of the language

  • Property Graph-like data model
  • Formal query semantics

Study of computational complexity (the language admits really efficient evaluation methods)

  • Evaluation problem is NL-complete
  • Enumeration of results is linear

Solution to the problem of large results

  • Efficient algorithm to compute result size
slide-57
SLIDE 57

www.liu.se