Defjning Property Graph Schemas using the GraphQL Schema Defjnitjon Language Olaf Hartjg @olafiartjg
What is GraphQL? ● State-of-the art approach to create Web APIs to retrieve data for Web and mobile applications ● Alternative to the notion of REST-based Web APIs ● Developed and used by Facebook since 2012 ● Made available to the public (open source) in 2015 – Spec and reference implementation ● Based on a simple, JSON-like query language Olaf Hartjg - Defjning Property Graph Schemas using the GraphQL Schema Defjnitjon Language 2
GraphQL Schema Defjnitjon Language (SDL) ● Language to define GraphQL schema ● Specifies the types of objects that can be queried when accessing a specific GraphQL Web API Olaf Hartjg - Defjning Property Graph Schemas using the GraphQL Schema Defjnitjon Language 3
GraphQL SDL Example declaration of an interface type declaration of an object type declaration of an object type and an implementation with its fields and their types with its fields and their types argument declaration of declaration of a union type a union type declaration of the query type (possible root fields of queries) Olaf Hartjg - Defjning Property Graph Schemas using the GraphQL Schema Defjnitjon Language 4
Can we use this language to defjne schemas for Property Graphs?
Property Graph Schemas with GraphQL SDL Example Property Graph schema defined using the GraphQL SDL type person { name: String! Image source: http://tinkerpop.apache.org/docs/3.4.0/tutorials/getting-started/ age: Int knows(weight:Float!): [person] @distinct @noloops created(weight:Float!): [software] @distinct @requiredForTarget } type software { name: String! lang: Language } enum Language { java javascript python } Olaf Hartjg - Defjning Property Graph Schemas using the GraphQL Schema Defjnitjon Language 6
Node Types and Node Propertjes type UserSession { id: ID! user: User! startTime: Time endTime: Time } scalar Time type User { id: ID! loginName: String! name: String } Olaf Hartjg - Defjning Property Graph Schemas using the GraphQL Schema Defjnitjon Language 7
(Outgoing) Edges type A { type B { name: String! favoriteA: A! favoriteB: B otherA: [A!] relatedA: [A] } } type C { otherC: [C!] @distinct @noloops b: [B] @distinct } type D { a: [A] @uniqueForTarget b: [B] @requiredForTarget c: [C] @uniqueForTarget @requiredForTarget } Olaf Hartjg - Defjning Property Graph Schemas using the GraphQL Schema Defjnitjon Language 8
Cardinality Restrictjons ● 1:1 relationship rel: B @uniqueForTarget ● 1:N relationship rel: B ● N:1 relationship rel: [B] @uniqueForTarget ● N:M relationship rel: [B] Olaf Hartjg - Defjning Property Graph Schemas using the GraphQL Schema Defjnitjon Language 9
Multjple Types of Target Nodes 1/2 type Person { id: ID! name: String! favoriteVehicle: Vehicle } union Vehicle = Car | Motorcycle type Car { brand: String! color: String } type Motorcycle { brand: String! } Olaf Hartjg - Defjning Property Graph Schemas using the GraphQL Schema Defjnitjon Language 10
Multjple Types of Target Nodes 2/2 type Person { id: ID! name: String! favoriteVehicle: Vehicle } interface Vehicle { brand: String! } type Car implements Vehicle { brand: String! color: String } type Motorcycle implements Vehicle { brand: String! } Olaf Hartjg - Defjning Property Graph Schemas using the GraphQL Schema Defjnitjon Language 11
Multjple Types of Source Nodes type Car { brand: String! color: String owner: Person } type Motorcycle { brand: String! owner: Person } type Person { name: String! } Olaf Hartjg - Defjning Property Graph Schemas using the GraphQL Schema Defjnitjon Language 12
Edge Propertjes type UserSession { id: ID! user(certainty:Float! comment:String): User! startTime: Time endTime: Time } Olaf Hartjg - Defjning Property Graph Schemas using the GraphQL Schema Defjnitjon Language 13
www.liu.se
Recommend
More recommend