Avaloq Graph QL Exploring Graph QL Solution Outline

  • Slides: 42
Download presentation
Avaloq Graph. QL Exploring Graph. QL / Solution Outline Loydl Unternehmensberatung, H. Loydl –

Avaloq Graph. QL Exploring Graph. QL / Solution Outline Loydl Unternehmensberatung, H. Loydl – 2017 1

Content • • • Explore Graph. QL Query Language What is Graph. QL, What

Content • • • Explore Graph. QL Query Language What is Graph. QL, What is it not REST Graph. QL Type System example Introspection, Composition, Resolving fields Mutation, N+1 queries problem solution, Security Why Graph. QL for Avaloq? POC (slide 25 …) Other stuff 2

Graph. QL Query Language – “Hello World” example { me { name } }

Graph. QL Query Language – “Hello World” example { me { name } } 3

{ { me { name } } “me” { “name” : “Harald Loydl” }

{ { me { name } } “me” { “name” : “Harald Loydl” } } 4

{ business. Partner(id: 1) { name } { “name”: “ACME AG” } } 5

{ business. Partner(id: 1) { name } { “name”: “ACME AG” } } 5

{ business. Partner(id: 1) { name address { street city country } } {

{ business. Partner(id: 1) { name address { street city country } } { “name”: “ACME AG”, “address”: { “street”: “Förlibuckstrasse”, “city”: “Zurich”, “country”: “Switzerland” } } } 6

{ business. Partner(id: 1) { name domicile: address(addr. Type: DOMICILE) { street city country

{ business. Partner(id: 1) { name domicile: address(addr. Type: DOMICILE) { street city country } postal: address(addr. Type: POSTAL) { street city country } } { “name”: “ACME AG”, “domicile”: { “street”: “Förlibuckstrasse”, “city”: “Zurich”, “country”: “Switzerland” } “postal”: { “street”: “Giessereistrasse”, “city”: “Zurich”, “country”: “Switzerland” } } } 7

{ business. Partner(id: 1) { name containers { name } } { “name”: “ACME

{ business. Partner(id: 1) { name containers { name } } { “name”: “ACME AG” “containers”: [ { “name”: “container 1” }, { “name”: “container 2” } ] } } 8

{ business. Partner(id: 1) { name containers { name positions { name } }

{ business. Partner(id: 1) { name containers { name positions { name } } { “name”: “ACME AG”, “containers”: [ { “name”: “container 1”, “positions”: [ { “name”: “pos 1” }, { “name”: “pos 2” } ] }, { “name”: “container 2”, “positions”: [ { “name”: “pos 1” }, 9

What Graph. QL is NOT - No Database - No Storage Engine - No

What Graph. QL is NOT - No Database - No Storage Engine - No Library - No Software to install (i. e. no Graph. QL server to buy and install) - Not bound to a programming language - Not bound to a network transport protocol (can use HTTP, websockets, …) 10

What Graph. QL IS - A Query Language for APIs - A Specification for

What Graph. QL IS - A Query Language for APIs - A Specification for servers to execute Graph. QL queries - A thin API and routing layer (field resolver can fetch data from different sources) 11

Disadvantages of REST GET /business. Partner/12274526535/containers - Hard to specify and implement advanced requests

Disadvantages of REST GET /business. Partner/12274526535/containers - Hard to specify and implement advanced requests with includes, excludes and especially with linked or nested resources - Generic endpoints typically overfetch data - Specific endpoints (per view) are getting pretty ugly to version hell - Over- or under-fetching of data is unavoidable - Too tight coupling between client (views) and server (endpoints) - documentation often outdated - developer uncertain about the responses (ambiguity, trial and error) 12

Avaloq Graph. QL Type System type Query { me: User business. Partner (id: Int):

Avaloq Graph. QL Type System type Query { me: User business. Partner (id: Int): Business. Partner } enum Address. Type. Enum { DOMICILE, POSTAL } type User { name: String } type Address { street: String city: String country: String } type Business. Partner { Id: Int name: String address(addr. Type: Address. Type. Enum): Address containers(first: Int): [Container] } type Container { name: String } 13

Type System on the Client? … Introspection { __schema { query. Type { name

Type System on the Client? … Introspection { __schema { query. Type { name } types { name fields { name type { kind name of. Type {name} } } 14

Graph. QL Introspection → Validation { business. Partner (id: 1231323) { name, icnatspel }

Graph. QL Introspection → Validation { business. Partner (id: 1231323) { name, icnatspel } } Unknown field “icnatspel” on type “Business. Partner” → IDE Integration → Code Generation → Auto-Documentation, Deprecation 15

Composition (Fragments) { business. Partner(id: 21252452) { name domicile: address(addr. Type: DOMICILE) {. .

Composition (Fragments) { business. Partner(id: 21252452) { name domicile: address(addr. Type: DOMICILE) {. . . address. Fragment } postal: address(addr. Type: POSTAL) {. . . address. Fragment } } } fragment address. Fragment on Address { street city country } 16

Resolving fields type Business. Partner { name: String address(addr. Type: Address. Type. Enum): Address

Resolving fields type Business. Partner { name: String address(addr. Type: Address. Type. Enum): Address containers(first: Int): [Container] } Fields like name, address and containers from the Type Definition on the left side are simple functions which actually resolve to a function. Fields expose a function named ‘resolve’ with parameters (parent-object, field-args, queryctx) where you implement how you fetch your data 17

Mutations mutation { create. Business. Partner(name: “Max Muster”, bp. Type: …) { id name

Mutations mutation { create. Business. Partner(name: “Max Muster”, bp. Type: …) { id name } } 18

N+1 Queries Problem Without a caching or batching mechanism, it's easy for a naive

N+1 Queries Problem Without a caching or batching mechanism, it's easy for a naive Graph. QL server to issue new database requests each time a field is resolved. Solution: Batching and Caching Further reading: • Data. Loader • Query batching in Apollo 19

Security “Oh no, you are letting your users query your database directly…? ” (the

Security “Oh no, you are letting your users query your database directly…? ” (the most awful thing ever) But… beside possible other solutions (like classic multi-tier)… • We define a Schema • We never expose something we don’t want to expose • We can have max execution time / Timeouts: after x seconds stop the query • We can limit the query depth or query complexity (define field costs) • . . . 20

Graph. QL – sample of more Features - Subscriptions. Client: “when this/that changes I

Graph. QL – sample of more Features - Subscriptions. Client: “when this/that changes I want updates”. (Graph. QL does not make any assumptions on how you implementation it) - Deferred Queries. Directive @defer Client: “show this GUI as fast as possible. But, there is a “deferred” part which can take longer to load. Show this part later when it is loaded” 21

Graph. QL - a data abstraction layer Graph. QL Existing Application Code Avaloq Credit

Graph. QL - a data abstraction layer Graph. QL Existing Application Code Avaloq Credit Risk Mgmt Compliance . . . 22

Why Graph. QL for Avaloq? Big picture • numerous clients, multiple platforms, overlapping features

Why Graph. QL for Avaloq? Big picture • numerous clients, multiple platforms, overlapping features • Apps around (micro)services instead of databases So everything is fine. . . Until you call the server…. 23

Why Graph. QL for Avaloq? • Data fetching performance needs to be massively improved

Why Graph. QL for Avaloq? • Data fetching performance needs to be massively improved • Graph. QL can describe the Avaloq Object Model / arbitrary levels of abstraction • The conceptual problems of REST APIs can be solved ( → Slide 11) • Decoupling the client from the server (decouple features from endpoints) 24

Demonstrate in the POC… 1. Graph. QL gives developers a much better understanding of

Demonstrate in the POC… 1. Graph. QL gives developers a much better understanding of Avaloq objects and their relations 2. Play around with Avaloq data, query and mutate data through an easy to understand query language (showcase Graphi. QL) 3. Significant performance improvements for GUIs incl. mobile 4. Angular, React, any GUI library can be used to build Frontends, simplicity 5. Clients get exactly the requested data (predictable, no ambiguity) 6. Clients get data in one round trip (Performance) 7. Batching and Caching 8. Enhancing the API without breaking clients code 9. Adding new GUI features without changing the server 25

Why Graph. QL for Avaloq? • Graph. QL makes it so much easier to

Why Graph. QL for Avaloq? • Graph. QL makes it so much easier to build public APIs aligned to Avaloq internal API i. e. the Avaloq Object Model + no mess with versions or breaking changes • Vastly simplified API release management (no breaking changes anymore, easy support for multiple versions out in the field, easy introduction of new features) • Easy to use and free available Graph. QL tools to enhance the developer experience, productivity, more fun to work with • Innovation 26

POC: Assumptions 1. Business Logic remains in ACP (obviously) 2. Kernel Layer Business Objects,

POC: Assumptions 1. Business Logic remains in ACP (obviously) 2. Kernel Layer Business Objects, doc Layer Objects, Avaloq WFC, Rules, etc. . so everything of relevance in terms of “Avaloq data and transactions” is accessible through internal PL/SQL function/procedure calls 3. Avaloq can expose this internal PL/SQL API for the needs of this POC and possibly above that for a Node. js production backend implementation 4. No need to change the internal PL/SQL API at all 5. Node. js in (or near) the backend is an opportunity for improvements (as discussed here) and does not violate basic architecture or security principles 6. Avaloq is interested to innovate and to start an incubation project when the outcome of this POC is perceived as an opportunity to improve things 27

POC: Architecture (high level) Browser, Native App, Frameworks, IDE Tools (e. g. Graphi. QL),

POC: Architecture (high level) Browser, Native App, Frameworks, IDE Tools (e. g. Graphi. QL), . . Avaloq Backend Graph. QL. js server (Node. js) Existing Application Code (internal PL/SQL API) Oracle DB driver for Node. js 28

POC: Areas of interest 1. Oracle Database Node. js Driver - Connection, Performance and

POC: Areas of interest 1. Oracle Database Node. js Driver - Connection, Performance and Security - Steps towards a “Node. js in or near the backend” production system 2. Graph. QL - Query and Mutate Avaloq Business Objects - Caching and Batching - Web/mobile GUIs using Graph. QL - Schema Customization: from an Avaloq Graph. QL “Standard” Schema to a customer specific Graph. QL Schema (Banks can adjust to their needs) 29

POC “alternative”: Graph. QL Server connects AMI Browser, Native App, Frameworks, IDE Tools (e.

POC “alternative”: Graph. QL Server connects AMI Browser, Native App, Frameworks, IDE Tools (e. g. Graphi. QL), . . Avaloq Backend Graph. QL Server AMI Messaging Interface 30

node-oracledb (Oracle DB Driver for Node. js) - maintained by Oracle Corp. - powers

node-oracledb (Oracle DB Driver for Node. js) - maintained by Oracle Corp. - powers high performance Oracle DB applications - stable - well documented - open source - doc: https: //github. com/oracle/node-oracledb/blob/master/doc/api. md 31

Graph. QL Server basic components Graph. QL Core (per language) lex, parse, validate, execute

Graph. QL Server basic components Graph. QL Core (per language) lex, parse, validate, execute queries based on Type Definitions (Schema) Graph. QL Application Code Avaloq + customization Server for Graph. QL endpoint e. g. resolvers, DB connect 32

Who is using Graph. QL 33

Who is using Graph. QL 33

Final Notes • Step-by-Step Transition to Graph. QL without breaking existing APIs • Start

Final Notes • Step-by-Step Transition to Graph. QL without breaking existing APIs • Start small • The technical integration seems to be very easy • The challenge is to define the right Graph. QL Schema 34

The Data Loading Problem Graph. QL: "the first true comprehensive solution to that data

The Data Loading Problem Graph. QL: "the first true comprehensive solution to that data loading problem" 35

Solution Endorsement by Angular and React: Angular 2: http: //dev. apollodata. com/angul ar 2/

Solution Endorsement by Angular and React: Angular 2: http: //dev. apollodata. com/angul ar 2/ React: http: //dev. apollodata. com/react/ 36

Data Fetching No. 1 on Angular Keynote: Apollo Graph. QL 37

Data Fetching No. 1 on Angular Keynote: Apollo Graph. QL 37

Graph. QL at Git. Hub 38

Graph. QL at Git. Hub 38

Before Graph. QL 39

Before Graph. QL 39

Now with Graph. QL 40

Now with Graph. QL 40

Backlog / slides & links Exploring Graph. QL by Lee Byron, Facebook 2015 Zero

Backlog / slides & links Exploring Graph. QL by Lee Byron, Facebook 2015 Zero to Graph. QL in 30 Minutes – Steven Luscher Implementing and Using Graph. QL at Git. Hub - Git. Hub Universe 2016 https: //githubengineering. com/the-github-graphql-api/ From REST to Graph. QL (Marc-Andre Giroux) - Full Stack Fest 2016 Dan Schafer - Graph. QL at Facebook at react-europe 2016 Lessons from 4 Years of Graph. QL Direct comparison REST / Graph. QL in one application (start at minute 28) Graph. QL Concepts Visualized https: //loydl. ch/2017/02/03/graphql/ https: //loydl. ch/2017/02/09/edoras-one-graphql-api/ 41

Graphi. QL in action: http: //graphql. org/swapi-graphql/ Star Wars API 42

Graphi. QL in action: http: //graphql. org/swapi-graphql/ Star Wars API 42