fundamental propertjes of the graphql language
play

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


  1. Fundamental Propertjes of the GraphQL Language Olaf Hartjg @olafiartjg Joint work with Jorge Pérez from the Universidad de Chile

  2. Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 2

  3. Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 3

  4. Why study the GraphQL language formally? Highlight intrinsic limitations of all possible implementations Identify optimization opportunities Clarify possible corner cases Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 4

  5. 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 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 5

  6. Formalizatjon of GraphQL

  7. Why? Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 7

  8. Why? Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 8

  9. Why? Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 9

  10. GraphQL Graphs (Our Formalizatjon) Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 10

  11. GraphQL Graphs (Our Formalizatjon) Typed nodes Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 11

  12. GraphQL Graphs (Our Formalizatjon) One special node Typed nodes Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 12

  13. GraphQL Graphs (Our Formalizatjon) Node properties One special node Typed nodes Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 13

  14. GraphQL Graphs (Our Formalizatjon) Edge properties Node properties One special node Typed nodes Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 14

  15. GraphQL Graphs (Our Formalizatjon) Edge properties Node properties One special node We also formalize the notions of GraphQL schema Typed nodes and schema satisfaction based on this data model Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 15

  16. Formalizatjon of Query Evaluatjon Functjon Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 16

  17. Formalizatjon of Query Evaluatjon Functjon u = friends { name } ⟧ ⟦ Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 17

  18. Formalizatjon of Query Evaluatjon Functjon u = friends { name } ⟧ friends: [ ] ⟦ Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 18

  19. Formalizatjon of Query Evaluatjon Functjon u v } { ⟦ w } ] = friends { name } ⟧ friends: [ { ⟦ name ⟧ name ⟧ ⟦ Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 19

  20. Formalizatjon of Query Evaluatjon Functjon u = friends { name } ⟧ friends: [ {name:R2-D2} {name:Han} ] ⟦ Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 20

  21. Formalizatjon of Query Evaluatjon Functjon hero[episode:EMPIRE] { friends {name} } ⟧ ⟦ Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 21

  22. Formalizatjon of Query Evaluatjon Functjon r ⟧ ⟦ hero[episode:EMPIRE] { friends {name} } Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 22

  23. Formalizatjon of Query Evaluatjon Functjon u } r = hero: { friends {name} ⟧ ⟧ ⟦ hero[episode:EMPIRE] { friends {name} } ⟦ Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 23

  24. Formalizatjon of Query Evaluatjon Functjon u } r = hero: { friends {name} ⟧ ⟧ ⟦ hero[episode:EMPIRE] { friends {name} } ⟦ = hero: { friends: [ {name:R2-D2} {name:Han} ] } Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 24

  25. Complexity Analysis Evaluation Problem

  26. Evaluatjon Problem of GraphQL GraphQL graph G GraphQL query q data value d Does d occur in the Does d occur in the result of q over G ? result of q over G ? yes no Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 26

  27. Complexity Classes PSPACE NP P Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 27

  28. Complexity of Evaluatjon Problems Relational Algebra SPARQL Conjunctive Queries BGPs (SPARQL) PSPACE NP P Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 28

  29. Complexity of Evaluatjon Problems Relational Algebra SPARQL Conjunctive Queries BGPs (SPARQL) PSPACE GraphQL NP NL P Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 29

  30. Complexity Analysis Enumeration Problem

  31. Non-Redundancy Valid query Invalid result hero[episode: EMPIRE] { hero { name name: Luke friends { friends: [ name { name: R2-D2} } { name: Han} id ] name id: 1000 friends { name: Luke id friends: [ } { id: 2001} } { id: 1002} ] } Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 31

  32. Non-Redundancy Valid query Correct result hero[episode: EMPIRE] { hero { name name: Luke friends { friends: [ name { name: R2-D2 } Id: 2001 } id { name: Han name Id: 1002 } friends { ] id id: 1000 } } } Fields are collected before answering Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 32

  33. Non-Redundancy Non-redundant query Correct result hero[episode: EMPIRE] { hero { name name: Luke friends { friends: [ name { name: R2-D2 id Id: 2001 } } { name: Han id Id: 1002 } } ] id: 1000 } Fields are collected before answering Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 33

  34. Another Complicatjon: Type Restrictjons Valid query Invalid result hero[episode: EMPIRE] { hero { name name: Luke friends { friends: [ on Droid { name } { name: R2-D2 on Human { id } name: R2-D2 } name { id: 1002 } name: Han } } ] } Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 34

  35. Another Complicatjon: Type Restrictjons Valid query Correct result hero[episode: EMPIRE] { hero { name name: Luke friends { friends: [ on Droid { name } { name: R2-D2 } on Human { id } { id: 1002 name name: Han } } ] } } Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 35

  36. Another Complicatjon: Type Restrictjons Valid query Correct result hero[episode: EMPIRE] { hero { name name: Luke friends { friends: [ on Droid { name } { name: R2-D2 } on Human { id name } { id: 1002 } name: Han } } ] } Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 36

  37. Ground-Typed Normal Form Ground-typed query Correct result hero[episode: EMPIRE] { hero { name name: Luke friends { friends: [ on Droid { name } { name: R2-D2 } on Human { id name } { id: 1002 } name: Han } } ] } Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 37

  38. 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 Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 38

  39. 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 hero { friends: [ { name:R2-D2} ] } Time to produce the complete query result depends linearly on the size of this result Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 39

  40. Complexity Analysis Result Size

  41. Results of GraphQL queries can be huge start { knows { knows { … { knows { name } }… } } } 2 N times Alice appears 2 N times in the result Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 41

  42. 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... Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 42

  43. 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 of q over a graph G depends linearly on the product (size of q ) × (size of G ) Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 43

  44. Result-Size Computatjon start { advisor { univ { name } } friend { univ { name } } } q 2 q 3 Result: start: { … … } size( q, r ) = 4 + size( q 2 ,u ) + size( q 3 ,u ) Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 44

  45. Result-Size Computatjon start { advisor { univ { name } } friend { univ { name } } } q 2 q 3 size( q 2 ,u ) = size( q 3 ,u ) = size( q, r ) = 4 + size( q 2 ,u ) + size( q 3 ,u ) Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 45

  46. Result-Size Computatjon q 4 start { advisor { univ { name } } friend { univ { name } } } q 3 q 2 size( q 2 ,u ) = 4 + size( q 4 ,v ) size( q 3 ,u ) = size( q, r ) = 4 + size( q 2 ,u ) + size( q 3 ,u ) Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 46

  47. Result-Size Computatjon q 4 start { advisor { univ { name } } friend { univ { name } } } q 5 q 3 q 2 size( q 4 ,v ) = 4 + size( q 5 ,w ) size( q 2 ,u ) = 4 + size( q 4 ,v ) size( q 3 ,u ) = size( q, r ) = 4 + size( q 2 ,u ) + size( q 3 ,u ) Olaf Hartjg – Fundamental Propertjes of the GraphQL Language 47

Recommend


More recommend