GraphQL Advanced
-
Upload
leanix-gmbh -
Category
Technology
-
view
137 -
download
2
Transcript of GraphQL Advanced
GRAPHQL ADVANCED
LeanIX, 2017
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)
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
"
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, …
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
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?
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?
8
Filter: Overview
Filter: By Fact Sheet IDs
9
Filter: By External IDs
10
Pro Tip: Get the exact Path by including the
external ID in the results and using autocomplete.
Filter: By exact Display Name
11
Attention: There are different
display name rules by Fact Sheet types, e.g.
including hierarchy or release.
Filter: By Quick Search
12
Attention: Optimized for performance,
descriptions etc. are not included.
Filter: By Full Text Search
13
14
Filter: By Filter Facet
15
Filter: By Filter Facet
16
Filter: By Filter Facet
17
Filter: By Filter Facet
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
Advanced: Use a subfilter (“show all applications that uses an IT Component of Provider Microsoft”)
19
Advanced: Use a filter on relations to limit the result set (“show all applications … and only the Microsoft relations”)
20
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?
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
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?
Patches Recap (1/2): Attributes
24
Use “validateOnly“ to test yourquery before executing it.
Patches Recap (2/2): Relations
25
Learn more about patches in Part 2 of the Webinar Series.
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
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?
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
Embedding GraphQL: Beyond the inline IDE
29
Swagger / curl
How to call GraphQL via REST
Java
Quick Walkthrough
Python
Edit application costs withGraphQL
Embedding GraphQL: Beyond the inline IDE
30
Swagger / curl
How to call GraphQL via REST
Java
Quick Walkthrough
Python
Edit application costs withGraphQL
Embedding GraphQL: Call GraphQL via REST
31
Create an API Token before openingSwagger
Embedding GraphQL: Call GraphQL via REST
32
Insert your API Token and press „Explore“
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.
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.
Embedding GraphQL: Beyond the inline IDE
35
Swagger / curl
How to call GraphQL via REST
Java
Quick Walkthrough
Python
Edit application costs withGraphQL
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
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
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
Embedding GraphQL: Beyond the inline IDE
39
Swagger / curl
How to call GraphQL via REST
Java
Quick Walkthrough
Python
Edit application costs withGraphQL
Embedding GraphQL: Editing application cost in Python – Create the connection
40https://dev.leanix.net/v4.0/docs/graphql-‐example-‐application-‐costs
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
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
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
44
“You can’t build your IT architecture today with yesterday’s tools and stay in business tomorrow”