GraphCoQL A mechanized formalization of GraphQL in Coq Toms Daz - - PowerPoint PPT Presentation

graphcoql
SMART_READER_LITE
LIVE PREVIEW

GraphCoQL A mechanized formalization of GraphQL in Coq Toms Daz - - PowerPoint PPT Presentation

GraphCoQL A mechanized formalization of GraphQL in Coq Toms Daz Federico Olmedo ric Tanter Millennium Institute Foundational Research on Data Certified Programs and Proofs New Orleans, USA January 2020 GraphQL Clases de ctedra


slide-1
SLIDE 1

GraphCoQL

Certified Programs and Proofs New Orleans, USA — January 2020

Federico Olmedo Tomás Díaz Éric Tanter

A mechanized formalization of GraphQL in Coq

Millennium Institute

Foundational Research on Data

slide-2
SLIDE 2

Clases de cátedra

GraphQL

2

Language for specifying the interfaces of web data services and their query mechanism

slide-3
SLIDE 3

Clases de cátedra

GraphQL

2

HTTP GET

Language for specifying the interfaces of web data services and their query mechanism

slide-4
SLIDE 4

Clases de cátedra

GraphQL

2

HTTP GET

query { artist(id:1000) { name artworks(role: ACTOR) { title } } }

Language for specifying the interfaces of web data services and their query mechanism

slide-5
SLIDE 5

Clases de cátedra

GraphQL

2

HTTP GET

query { artist(id:1000) { name artworks(role: ACTOR) { title } } }

Language for specifying the interfaces of web data services and their query mechanism

slide-6
SLIDE 6

Clases de cátedra

GraphQL

2

HTTP GET

query { artist(id:1000) { name artworks(role: ACTOR) { title } } }

Language for specifying the interfaces of web data services and their query mechanism

slide-7
SLIDE 7

Clases de cátedra

GraphQL

2

HTTP GET

query { artist(id:1000) { name artworks(role: ACTOR) { title } } }

Language for specifying the interfaces of web data services and their query mechanism

slide-8
SLIDE 8

{ “artist” : { “name” : “Tom Hanks”, “artworks” : [ { “title” : “Toy Story”, }, { “title” : “Forrest Gump”, }, … ] } }

Clases de cátedra

GraphQL

2

HTTP GET

query { artist(id:1000) { name artworks(role: ACTOR) { title } } }

Language for specifying the interfaces of web data services and their query mechanism

slide-9
SLIDE 9

{ “artist” : { “name” : “Tom Hanks”, “artworks” : [ { “title” : “Toy Story”, }, { “title” : “Forrest Gump”, }, … ] } }

Clases de cátedra

GraphQL

2

HTTP GET

query { artist(id:1000) { name artworks(role: ACTOR) { title } } }

Language for specifying the interfaces of web data services and their query mechanism

slide-10
SLIDE 10

{ “artist” : { “name” : “Tom Hanks”, “artworks” : [ { “title” : “Toy Story”, }, { “title” : “Forrest Gump”, }, … ] } }

Clases de cátedra

GraphQL

2

HTTP GET

query { artist(id:1000) { name artworks(role: ACTOR) { title } } }

Language for specifying the interfaces of web data services and their query mechanism

slide-11
SLIDE 11

Clases de cátedra

Industry involvement with GraphQL

3

2012 2015+

slide-12
SLIDE 12

Clases de cátedra

First language formalization [Hartig & Pérez, WWW’18]

4

Paper & pencil formalization to study complexity properties.

Jf[]Ku

G =

( f:(u, f[]) if (u, f[]) 2 dom() f:null else. J`:f[]Ku

G =

( `:(u, f[]) if (u, f[]) 2 dom() `:null else. Jf[]{}Ku

G =

       f:[{JK1

G } · · · {JKk G }]

if typeS(f) 2 LT and {1, ... ,k } = {i | (u, f[],i ) 2 E} f:{ JK

G }

if typeS(f) < LT and (u, f[],) 2 E f:null if typeS(f) < LT and there is no 2 N s.t. (u, f[],) 2 E J`:f[]{}Ku

G =

       `:[{JK1

G } · · · {JKk G }]

if typeS(f) 2 LT and {1, ... ,k } = {i | (u, f[],i ) 2 E} `:{ JK

G }

if typeS(f) < LT and (u, f[],) 2 E `:null if typeS(f) < LT and there is no 2 N s.t. (u, f[],) 2 E Jon t{}Ku

G =

       JKu

G

if t 2 OT and (u) = t, or t 2 IT and (u) 2 implementationS(t), or t 2 UT and (u) 2 unionS(t)

  • in other case.

J1 · · ·kKu

G = collect(J1Ku G · · · JkKu G )

Figure 5: Semantics of a GraphQL query.

slide-13
SLIDE 13

Clases de cátedra

First language formalization [Hartig & Pérez, WWW’18]

4

Paper & pencil formalization to study complexity properties.

Jf[]Ku

G =

( f:(u, f[]) if (u, f[]) 2 dom() f:null else. J`:f[]Ku

G =

( `:(u, f[]) if (u, f[]) 2 dom() `:null else. Jf[]{}Ku

G =

       f:[{JK1

G } · · · {JKk G }]

if typeS(f) 2 LT and {1, ... ,k } = {i | (u, f[],i ) 2 E} f:{ JK

G }

if typeS(f) < LT and (u, f[],) 2 E f:null if typeS(f) < LT and there is no 2 N s.t. (u, f[],) 2 E J`:f[]{}Ku

G =

       `:[{JK1

G } · · · {JKk G }]

if typeS(f) 2 LT and {1, ... ,k } = {i | (u, f[],i ) 2 E} `:{ JK

G }

if typeS(f) < LT and (u, f[],) 2 E `:null if typeS(f) < LT and there is no 2 N s.t. (u, f[],) 2 E Jon t{}Ku

G =

       JKu

G

if t 2 OT and (u) = t, or t 2 IT and (u) 2 implementationS(t), or t 2 UT and (u) 2 unionS(t)

  • in other case.

J1 · · ·kKu

G = collect(J1Ku G · · · JkKu G )

Figure 5: Semantics of a GraphQL query.

Missing proofs about fundamental properties

slide-14
SLIDE 14

Clases de cátedra

Our contribution

5

First mechanized formalization of GraphQL in the Coq proof assistant

GraphCoQL

slide-15
SLIDE 15

Clases de cátedra

Schema

6

Describes how data is structured and queried

type Artist { id: ID name: String artworks(role:Role): [Artwork] } interface Movie { id: ID title: String year: Int cast: [Artist] } type Fiction implements Movie { … } type Animation implements Movie { … style: Style } enum Role { ACTOR DIRECTOR WRITER } union Artwork = Fiction | Animation | Book type Book { … } type Query { artist(id:ID): Artist movie(id:ID): Movie }

slide-16
SLIDE 16

Clases de cátedra

Schema

6

Describes how data is structured and queried

  • bject

type

type Artist { id: ID name: String artworks(role:Role): [Artwork] } interface Movie { id: ID title: String year: Int cast: [Artist] } type Fiction implements Movie { … } type Animation implements Movie { … style: Style } enum Role { ACTOR DIRECTOR WRITER } union Artwork = Fiction | Animation | Book type Book { … } type Query { artist(id:ID): Artist movie(id:ID): Movie }

slide-17
SLIDE 17

Clases de cátedra

Schema

6

Describes how data is structured and queried

interface type

  • bject

type

type Artist { id: ID name: String artworks(role:Role): [Artwork] } interface Movie { id: ID title: String year: Int cast: [Artist] } type Fiction implements Movie { … } type Animation implements Movie { … style: Style } enum Role { ACTOR DIRECTOR WRITER } union Artwork = Fiction | Animation | Book type Book { … } type Query { artist(id:ID): Artist movie(id:ID): Movie }

slide-18
SLIDE 18

Clases de cátedra

Schema

6

Describes how data is structured and queried

interface type

  • bject

type

type Artist { id: ID name: String artworks(role:Role): [Artwork] } interface Movie { id: ID title: String year: Int cast: [Artist] } type Fiction implements Movie { … } type Animation implements Movie { … style: Style } enum Role { ACTOR DIRECTOR WRITER } union Artwork = Fiction | Animation | Book type Book { … } type Query { artist(id:ID): Artist movie(id:ID): Movie }

slide-19
SLIDE 19

Clases de cátedra

Schema

6

Describes how data is structured and queried

interface type

  • bject

type enumeration type

type Artist { id: ID name: String artworks(role:Role): [Artwork] } interface Movie { id: ID title: String year: Int cast: [Artist] } type Fiction implements Movie { … } type Animation implements Movie { … style: Style } enum Role { ACTOR DIRECTOR WRITER } union Artwork = Fiction | Animation | Book type Book { … } type Query { artist(id:ID): Artist movie(id:ID): Movie }

slide-20
SLIDE 20

Clases de cátedra

Schema

6

Describes how data is structured and queried

interface type

  • bject

type enumeration type union type

type Artist { id: ID name: String artworks(role:Role): [Artwork] } interface Movie { id: ID title: String year: Int cast: [Artist] } type Fiction implements Movie { … } type Animation implements Movie { … style: Style } enum Role { ACTOR DIRECTOR WRITER } union Artwork = Fiction | Animation | Book type Book { … } type Query { artist(id:ID): Artist movie(id:ID): Movie }

slide-21
SLIDE 21

Clases de cátedra

Schema

6

Describes how data is structured and queried

interface type

  • bject

type entry points for querying the dataset enumeration type union type

type Artist { id: ID name: String artworks(role:Role): [Artwork] } interface Movie { id: ID title: String year: Int cast: [Artist] } type Fiction implements Movie { … } type Animation implements Movie { … style: Style } enum Role { ACTOR DIRECTOR WRITER } union Artwork = Fiction | Animation | Book type Book { … } type Query { artist(id:ID): Artist movie(id:ID): Movie }

slide-22
SLIDE 22

Clases de cátedra

Schema

7

Describes how data is structured and queried

slide-23
SLIDE 23

Clases de cátedra

Graph data model

8

Datasets are modeled as directed property graphs, with labeled edges and typed nodes.

slide-24
SLIDE 24

Clases de cátedra

Graph data model

8

Datasets are modeled as directed property graphs, with labeled edges and typed nodes.

Artist

id: 1000 name: “Tom Hanks”

slide-25
SLIDE 25

Clases de cátedra

Graph data model

8

Datasets are modeled as directed property graphs, with labeled edges and typed nodes.

Artist Fiction

id: 2000 title: “Forrest Gump” year: 1994 id: 1000 name: “Tom Hanks”

Animation

id: 2001 title: “Toy Story” year: 1995 style: “3D" artworks[role:ACTOR] artworks[role:ACTOR]

slide-26
SLIDE 26

Clases de cátedra

Graph data model

8

Datasets are modeled as directed property graphs, with labeled edges and typed nodes.

Artist Fiction

id: 2000 title: “Forrest Gump” year: 1994 id: 1000 name: “Tom Hanks”

Animation

id: 2001 title: “Toy Story” year: 1995 style: “3D" artworks[role:ACTOR] artworks[role:ACTOR] cast cast

slide-27
SLIDE 27

Clases de cátedra

Graph data model

8

Datasets are modeled as directed property graphs, with labeled edges and typed nodes.

Book Artist Fiction

id: 3000 title: “Uncommon Type” year: 2017 ISBN: 1101946156 id: 2000 title: “Forrest Gump” year: 1994 id: 1000 name: “Tom Hanks”

Animation

id: 2001 title: “Toy Story” year: 1995 style: “3D" artworks[role:ACTOR] artworks[role:ACTOR] cast cast artworks[role:WRITER] author

slide-28
SLIDE 28

Clases de cátedra

Graph data model

8

Datasets are modeled as directed property graphs, with labeled edges and typed nodes.

Query Book Artist Fiction

artist[id:1000] id: 3000 title: “Uncommon Type” year: 2017 ISBN: 1101946156 id: 2000 title: “Forrest Gump” year: 1994 id: 1000 name: “Tom Hanks”

Animation

id: 2001 title: “Toy Story” year: 1995 style: “3D" movie[id:2001] movie[id:2000] artworks[role:ACTOR] artworks[role:ACTOR] cast cast artworks[role:WRITER] author

slide-29
SLIDE 29

query { artist(id:1000) { name artworks(role: ACTOR) { title } } }

Clases de cátedra

Query evaluation

9

Queries are evaluated by traversing the graph and collecting nodes’ properties

Response (à la JSON) Query Dataset

{ “artist” : { “name” : “Tom Hanks”, “artworks” : [ { … }, { … }, ] } }

slide-30
SLIDE 30

Clases de cátedra

Query evaluation

10

Queries are evaluated by traversing the graph and collecting nodes’ properties

Response (à la JSON) Query Dataset

{ “artist” : { “name” : “Tom Hanks”, “artworks” : [ { … }, { … }, ] } } query { artist(id:1000) { name artworks(role: ACTOR) { title } } }

slide-31
SLIDE 31

Clases de cátedra

Query evaluation

11

Queries are evaluated by traversing the graph and collecting nodes’ properties

Response (à la JSON) Query Dataset

{ “artist” : { “name” : “Tom Hanks”, “artworks” : [ { … }, { … }, ] } } query { artist(id:1000) { name artworks(role: ACTOR) { title } } }

slide-32
SLIDE 32

Clases de cátedra

Query evaluation

12

Queries are evaluated by traversing the graph and collecting nodes’ properties

Response (à la JSON) Query Dataset

{ “artist” : { “name” : “Tom Hanks”, “artworks” : [ { … }, { … }, ] } } query { artist(id:1000) { name artworks(role: ACTOR) { title } } }

slide-33
SLIDE 33

Clases de cátedra

Query evaluation

13

Queries are evaluated by traversing the graph and collecting nodes’ properties

Response (à la JSON) Query Dataset

{ “artist” : { “name” : “Tom Hanks”, “artworks” : [ { “title” : … }, { “title” : … }, ] } } query { artist(id:1000) { name artworks(role: ACTOR) { title } } }

slide-34
SLIDE 34

Clases de cátedra

Query evaluation - Peculiarities

14

Query evaluation is not compositional

slide-35
SLIDE 35

Clases de cátedra

Query evaluation - Peculiarities

14

Query evaluation is not compositional

query { artist(id:1000) { name } artist(id:1000) { artworks(role: ACTOR) { title } } }

slide-36
SLIDE 36

Clases de cátedra

Query evaluation - Peculiarities

14

Query evaluation is not compositional

query { artist(id:1000) { name } artist(id:1000) { artworks(role: ACTOR) { title } } }

slide-37
SLIDE 37

Clases de cátedra

Query evaluation - Peculiarities

14

Query evaluation is not compositional

query { artist(id:1000) { name } artist(id:1000) { artworks(role: ACTOR) { title } } } { “artist” : { “name” : “Tom Hanks”, }, “artist” : { “artworks” : [ { … }, { … }, ] } }

slide-38
SLIDE 38

Clases de cátedra

Query evaluation - Singularities

15

Selections are “factored-out” in between the recursive calls

Query evaluation is not compositional

{ “artist” : { “name” : “Tom Hanks”, “artworks” : [ { … }, { … }, ] } } query { artist(id:1000) { name } artist(id:1000) { artworks(role: ACTOR) { title } } }

slide-39
SLIDE 39

Clases de cátedra

Query evaluation - Singularities

15

Selections are “factored-out” in between the recursive calls

This makes reasoning significantly harder

Query evaluation is not compositional

{ “artist” : { “name” : “Tom Hanks”, “artworks” : [ { … }, { … }, ] } } query { artist(id:1000) { name } artist(id:1000) { artworks(role: ACTOR) { title } } }

slide-40
SLIDE 40

Application

slide-41
SLIDE 41

Clases de cátedra

Normalization [H&P, WWW’18]

17

slide-42
SLIDE 42

Clases de cátedra

Normalization [H&P, WWW’18]

17

Queries admit a normal form that can be evaluated purely compositionally and significantly simplifies reasoning

slide-43
SLIDE 43

Clases de cátedra

Normalization [H&P, WWW’18]

17

Queries admit a normal form that can be evaluated purely compositionally and significantly simplifies reasoning

👏

Normalization procedure not provided

👏

No correctness proof

But….

slide-44
SLIDE 44

Clases de cátedra

Query normalization

18

slide-45
SLIDE 45

Clases de cátedra

Query normalization

18

  • Certified normalization algorithm

e with

u σs. Theorem normalize_preserves_semantics : ∀ (φ : query) (s : wfGraphQLSchema) (g : conformedGraph s), eval_query (normalize s φ) g s = eval_query φ g s. Theorem normalized_query_is_in_nf : ∀ (φ : query) (s : wfGraphQLSchema), is_in_normal_form s (normalize s φ).

slide-46
SLIDE 46

Clases de cátedra

Query normalization

18

  • Certified normalization algorithm
  • Simplified evaluation for queries in normal form

e with

u σs. Theorem normalize_preserves_semantics : ∀ (φ : query) (s : wfGraphQLSchema) (g : conformedGraph s), eval_query (normalize s φ) g s = eval_query φ g s. Theorem normalized_query_is_in_nf : ∀ (φ : query) (s : wfGraphQLSchema), is_in_normal_form s (normalize s φ). Theorem simpl_eval_correctness : ∀ (φ : query) (s : wfGraphQLSchema) (g : conformedGraph s), is_in_normal_form s φ -> eval_query φ g s = simpl_eval_query φ g s.

slide-47
SLIDE 47

Formalization evaluation and details

slide-48
SLIDE 48

Clases de cátedra

Evaluation

20

Effectivity Uncovered two issues in H&P formalization:

  • Flawed definition of normal form
  • Incomplete set of equivalence rules for normalization
slide-49
SLIDE 49

Clases de cátedra

Evaluation

20

Effectivity Uncovered two issues in H&P formalization:

  • Flawed definition of normal form
  • Incomplete set of equivalence rules for normalization

Faithfulness Validated with a series of examples from different sources:

  • Examples (41) from the SPEC validation section*
  • Star Wars example from GraphQL reference implementation
  • Example used in H&P

* https://graphql.github.io/graphql-spec/June2018/#sec-Validation

slide-50
SLIDE 50

Clases de cátedra

Conclusion

21

  • First mechanized formalization of GraphQL in the Coq proof assistant
  • Certified query normalization algorithm
  • Uncover issues in initial formalization [H&P, WWW18]

Contribution

slide-51
SLIDE 51

Clases de cátedra

Conclusion

21

  • First mechanized formalization of GraphQL in the Coq proof assistant
  • Certified query normalization algorithm
  • Uncover issues in initial formalization [H&P, WWW18]
  • Further GraphQL features
  • Extraction (certified reference implementation)
  • More general data models

Contribution Future work

slide-52
SLIDE 52

Clases de cátedra

Conclusion

21

  • First mechanized formalization of GraphQL in the Coq proof assistant
  • Certified query normalization algorithm
  • Uncover issues in initial formalization [H&P, WWW18]

Thanks!

  • Further GraphQL features
  • Extraction (certified reference implementation)
  • More general data models

Contribution Future work