GraphQL Advanced

44
GRAPHQL ADVANCED LeanIX, 2017

Transcript of GraphQL Advanced

Page 1: GraphQL Advanced

GRAPHQL ADVANCED

LeanIX,  2017

Page 2: GraphQL Advanced

What  you  will  learn

2

• Quick  recap  from  Part  1

• Deep  Dive:  Filter,  Paging,  Patches,  Revisions

• How  to  embed  GraphQL in  Swagger,  curl,  Java

• Concrete  use  case  (based  on  Python)

Page 3: GraphQL Advanced

Recap  (1/3):  How  the  way  to  embed  LeanIX  is  evolving

3

Data  input

!Upload

Web  UI

Survey

Data  usage

Download

Web  UI

Mobile  App

ITSM

BPM

Vendor  Lifecycles

Metrics

BPM

ITSM

Universe  of    modern  IT  management  tools

Universe  of  modern  reporting  solutions

Single  source  of  truth

Out-­‐of-­‐the-­‐box  inte-­‐

grations

Integrated  information  

hub

"

Page 4: GraphQL Advanced

Recap  (2/3):  Basic  Concepts  -­‐ Query  and  Mutation

4

query

Retrieve  Fact  Sheet  data,  Subscriptions,  Tags,  ….

mutation

Create,  Update  or  Delete  Fact  Sheets,  Subscriptions,  Tags,  …

Page 5: GraphQL Advanced

Recap (3/3): How to use the integrated GraphQL IDE from your LeanIX workspace

5

1

2

3

5

4

1 Access  GraphiQL from  the  admin  area

2Use  auto-­‐completion  and  prettify  to  formulate  and  run  your  query

3 Optional:  Use  variables  to  better  structure  your  query

4Access  the  results  directly,  iterate  until  you  have  got  all  data  you  need

5Use  the  built-­‐in  reference    for  details

Page 6: GraphQL Advanced

Advanced  Concepts:  Filter,  Paging,  Patches,  Revisions

6

Filter

How to formulate yourqueries to get precisely your

result?

Paging

How to querylarge  amounts of data in  productive settings?

Patches

How to leveragemutations for different  type  

of changes?

Revisions

How to support a  stableproductive environment with

concurrent changes?

Page 7: GraphQL Advanced

Advanced  Concepts:  Filter,  Paging,  Patches,  Revisions

7

Filter

How to formulate yourqueries to get precisely your

result?

Paging

How to querylarge  amounts of data in  productive settings?  

Patches

How to leveragemutations for different  type  

of changes?

Revisions

How to support a  stableproductive environment with

concurrent changes?

Page 8: GraphQL Advanced

8

Filter:  Overview

Page 9: GraphQL Advanced

Filter:  By  Fact  Sheet  IDs

9

Page 10: GraphQL Advanced

Filter:  By  External  IDs

10

Pro  Tip:  Get  the  exact  Path  by  including  the  

external  ID  in  the  results  and  using  autocomplete.

Page 11: GraphQL Advanced

Filter:  By  exact  Display  Name

11

Attention:  There  are  different  

display  name  rules  by  Fact  Sheet  types,  e.g.  

including  hierarchy  or  release.

Page 12: GraphQL Advanced

Filter:  By  Quick  Search

12

Attention:  Optimized  for  performance,  

descriptions  etc.  are  not  included.

Page 13: GraphQL Advanced

Filter:  By  Full  Text  Search

13

Page 14: GraphQL Advanced

14

Filter:  By  Filter  Facet

Page 15: GraphQL Advanced

15

Filter:  By  Filter  Facet

Page 16: GraphQL Advanced

16

Filter:  By  Filter  Facet

Page 17: GraphQL Advanced

17

Filter:  By  Filter  Facet

Page 18: GraphQL Advanced

Pro  Tip:  Use  Browser  Developer  Tools  as  reference  for  Facet  Keys  and  Values  

18

See  e.g.  https://developers.google.com/web/tools/chrome-­‐devtools/

or  https://docs.microsoft.com/en-­‐us/microsoft-­‐edge/devtools-­‐

guide

Page 19: GraphQL Advanced

Advanced:  Use  a  subfilter (“show  all  applications  that  uses  an  IT  Component  of  Provider  Microsoft”)

19

Page 20: GraphQL Advanced

Advanced:  Use  a  filter  on  relations  to  limit  the  result  set  (“show  all  applications  …  and  only  the  Microsoft  relations”)

20

Page 21: GraphQL Advanced

Advanced  Concepts:  Filter,  Paging,  Patches,  Revisions

21

Filter

How to formulate yourqueries to get precisely your

result?

Paging

How to querylarge  amounts of data in  productive settings ?

Patches

How to leveragemutations for different  type  

of changes?

Revisions

How to support a  stableproductive environment with

concurrent changes?

Page 22: GraphQL Advanced

Paging:  Retrieve  large  amount  of  Fact  Sheets

22

1.  Include  pageinfo {}  in  your  

query

2.  Obtain  a  cursor

3.  Use  “after”  with  the  cursor

4.  Repeat  until  “hasNextPages”  is  

false

Page 23: GraphQL Advanced

Advanced  Concepts:  Filter,  Paging,  Patches,  Revisions

23

Filter

How to formulate yourqueries to get precisely your

result?

Paging

How to querylarge  amounts of data in  productive settings?  

Patches

How to leveragemutations for different  type  

of changes?

Revisions

How to support a  stableproductive environment with

concurrent changes?

Page 24: GraphQL Advanced

Patches  Recap  (1/2):  Attributes

24

Use “validateOnly“  to test yourquery before executing it.

Page 25: GraphQL Advanced

Patches  Recap  (2/2):  Relations

25

Learn more about patches in  Part  2  of the Webinar  Series.

Page 26: GraphQL Advanced

Patches:  Summary

26

Operator

Path

Value

• Add• Replace  • Remove

A

B

C

• /attributeName

• /relationName/new_<idx>  for  new  relations

• /relationName/<relationId>  for  existing  relations

• String  for  attribute• JSON  Object  for  Relations  or  ExternalIDs• Array  for  Tag  /  Multi-­‐Select

-­‐ It’s  always  good  practice  to  work  with  multiple  patches  in  one  API  call-­‐ Use  the  browser  developer  tools  as  reference  for  exact  syntax  if  unsure

Page 27: GraphQL Advanced

Advanced  Concepts:  Filter,  Paging,  Patches,  Revisions

27

Filter

How to formulate yourqueries to get precisely your

result?

Paging

How to querylarge  amounts of data in  productive settings?

Patches

How to leveragemutations for different  type  

of changes?

Revisions

How to support a  stableproductive environment with

concurrent changes?

Page 28: GraphQL Advanced

28

Revisions:  Clear  conflict  resolution  strategy

1.  Start  to  edit  a  Fact  Sheet  in  the  

UI

2.  Retrieve  the  Fact  Sheet  via  GraphQL =>  revision:  23

3.  Update  the  Fact  Sheet  via  GraphQL =>  revision:  24

4.  Save  in  the  UI  – user  will  get  a  

conflict

Page 29: GraphQL Advanced

Embedding  GraphQL:  Beyond  the  inline  IDE

29

Swagger  /  curl

How to call GraphQL via  REST

Java

Quick  Walkthrough

Python

Edit  application costs withGraphQL

Page 30: GraphQL Advanced

Embedding  GraphQL:  Beyond  the  inline  IDE

30

Swagger  /  curl

How to call GraphQL via  REST

Java

Quick  Walkthrough

Python

Edit  application costs withGraphQL

Page 31: GraphQL Advanced

Embedding  GraphQL:  Call  GraphQL via  REST

31

Create  an  API  Token  before openingSwagger

Page 32: GraphQL Advanced

Embedding  GraphQL:  Call  GraphQL via  REST

32

Insert  your API  Token  and press  „Explore“

Page 33: GraphQL Advanced

33

Embedding  GraphQL:  Call  GraphQL via  REST  -­‐ Query

Insert  your Query  andpress  „Try  it out“

Get your response

Get the curlcommand.  See  

https://dev.leanix.net/v4.0/docs/authentication as well.

Page 34: GraphQL Advanced

34

Embedding  GraphQL:  Call  GraphQL via  REST  -­‐ Mutation

Insert  yourMutation  andpress  „Try  it

out“

Get yourresponse

Get the curlcommand.  See  

https://dev.leanix.net/v4.0/docs/authentication as

well.

Page 35: GraphQL Advanced

Embedding  GraphQL:  Beyond  the  inline  IDE

35

Swagger  /  curl

How to call GraphQL via  REST

Java

Quick  Walkthrough

Python

Edit  application costs withGraphQL

Page 36: GraphQL Advanced

Embedding  GraphQL:  Call  GraphQL from  Java

36

1

2

3

4

1 Get  dependencies  via  Maven

2 Connection  with  help  of  SDK

3 Get  a  Fact  Sheet  (details  follow)

4 Update  a  Fact  Sheet  (details  follow)

See  https://dev.leanix.net/v4.0/docs/graphql-­‐in-­‐java

Page 37: GraphQL Advanced

Embedding  GraphQL:  Call  GraphQL from  Java  –Get  Fact  Sheet  By  Id

37

1

5

3

2

4

5

Use  an  abstract  base  class  for  efficiency1

Use  standard  JSON  libraries2

Build  the  query3

Execute  the  query4

Handle  errors

Page 38: GraphQL Advanced

Embedding  GraphQL:  Call  GraphQL from  Java  –Update  Fact  Sheet  

38

Same  base  class  as  before1

Create  the  required  patches2

Helper  method  to  handle  mutations3

1

2

3

Page 39: GraphQL Advanced

Embedding  GraphQL:  Beyond  the  inline  IDE

39

Swagger  /  curl

How to call GraphQL via  REST

Java

Quick  Walkthrough

Python

Edit  application costs withGraphQL

Page 40: GraphQL Advanced

Embedding  GraphQL:  Editing  application  cost  in  Python  – Create  the  connection

40https://dev.leanix.net/v4.0/docs/graphql-­‐example-­‐application-­‐costs

Page 41: GraphQL Advanced

Embedding  GraphQL:  Editing  application  cost  in  Python  – Initial  import

41

Use  https://pandas.pydata.org/ to  read  the  CSV1

Use  multiline  strings  to  represent  the  queries  /  mutations2

Use  Python  standard  JSON  processing  for  dealing  with  the  results

3

1

2

3

Page 42: GraphQL Advanced

Embedding  GraphQL:  Editing  application  cost  in  Python  – Update

42

Use  https://pandas.pydata.org/ to  read  the  CSV1

Use  multiline  strings  to  represent  the  queries  /  mutations2

Use  Python  standard  JSON  processing  for  dealing  with  the  results

3

1

2

3

Page 43: GraphQL Advanced

Summary:  What  you’ve  learnt  and  where  to  learn  more  

43

What  have  you  learnt?

Where  to  learn  more?

Webinar  Part  3  –Custom  Reports

• Advanced  concepts  (filter,  paging,  patches,  revisions)• How  to  embed  GraphQL (via  Swagger,  curl,  Java,  Python)

A

B

C

• Check  https://dev.leanix.net or  https://graphql.org• Reach  out  to  [email protected] for  feedback,  questions  and  ideas

• Learn  how  to  upload  your  own  JavaScript  reports  based  on  GraphQL into  LeanIX

Page 44: GraphQL Advanced

44

“You  can’t  build  your  IT  architecture  today  with  yesterday’s  tools  and  stay  in  business  tomorrow”