Learn how to build advanced GraphQL queries, how to work with filters and patches and how to embed GraphQL in languages like Python and Java. These slides are the second set in our webinar series on GraphQL.
2. 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)
3. 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
"
5. 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
2
Use
auto-‐completion
and
prettify
to
formulate
and
run
your
query
3
Optional:
Use
variables
to
better
structure
your
query
4
Access
the
results
directly,
iterate
until
you
have
got
all
data
you
need
5
Use
the
built-‐in
reference
for
details
6. Advanced
Concepts:
Filter,
Paging,
Patches,
Revisions
6
Filter
How to formulate your
queries to get precisely your
result?
Paging
How to query
large
amounts of data in
productive settings?
Patches
How to leverage
mutations for different
type
of changes?
Revisions
How to support a
stable
productive environment with
concurrent changes?
7. Advanced
Concepts:
Filter,
Paging,
Patches,
Revisions
7
Filter
How to formulate your
queries to get precisely your
result?
Paging
How to query
large
amounts of data in
productive settings?
Patches
How to leverage
mutations for different
type
of changes?
Revisions
How to support a
stable
productive environment with
concurrent changes?
18. 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
19. Advanced:
Use
a
subfilter (“show
all
applications
that
uses
an
IT
Component
of
Provider
Microsoft”)
19
20. Advanced:
Use
a
filter
on
relations
to
limit
the
result
set
(“show
all
applications
…
and
only
the
Microsoft
relations”)
20
21. Advanced
Concepts:
Filter,
Paging,
Patches,
Revisions
21
Filter
How to formulate your
queries to get precisely your
result?
Paging
How to query
large
amounts of data in
productive settings ?
Patches
How to leverage
mutations for different
type
of changes?
Revisions
How to support a
stable
productive environment with
concurrent changes?
22. 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
23. Advanced
Concepts:
Filter,
Paging,
Patches,
Revisions
23
Filter
How to formulate your
queries to get precisely your
result?
Paging
How to query
large
amounts of data in
productive settings?
Patches
How to leverage
mutations for different
type
of changes?
Revisions
How to support a
stable
productive environment with
concurrent changes?
24. Patches
Recap
(1/2):
Attributes
24
Use “validateOnly“
to test your
query before executing it.
25. Patches
Recap
(2/2):
Relations
25
Learn more about patches in
Part
2
of the Webinar
Series.
26. 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
27. Advanced
Concepts:
Filter,
Paging,
Patches,
Revisions
27
Filter
How to formulate your
queries to get precisely your
result?
Paging
How to query
large
amounts of data in
productive settings?
Patches
How to leverage
mutations for different
type
of changes?
Revisions
How to support a
stable
productive environment with
concurrent changes?
28. 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
29. Embedding
GraphQL:
Beyond
the
inline
IDE
29
Swagger
/
curl
How to call GraphQL via
REST
Java
Quick
Walkthrough
Python
Edit
application costs with
GraphQL
30. Embedding
GraphQL:
Beyond
the
inline
IDE
30
Swagger
/
curl
How to call GraphQL via
REST
Java
Quick
Walkthrough
Python
Edit
application costs with
GraphQL
33. 33
Embedding
GraphQL:
Call
GraphQL via
REST
-‐ Query
Insert
your Query
and
press
„Try
it out“
Get your response
Get the curl
command.
See
https://dev.leanix.
net/v4.0/docs/aut
hentication as well.
34. 34
Embedding
GraphQL:
Call
GraphQL via
REST
-‐ Mutation
Insert
your
Mutation
and
press
„Try
it
out“
Get your
response
Get the curl
command.
See
https://dev.leanix.
net/v4.0/docs/aut
hentication as
well.
35. Embedding
GraphQL:
Beyond
the
inline
IDE
35
Swagger
/
curl
How to call GraphQL via
REST
Java
Quick
Walkthrough
Python
Edit
application costs with
GraphQL
36. 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
37. 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
38. 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
39. Embedding
GraphQL:
Beyond
the
inline
IDE
39
Swagger
/
curl
How to call GraphQL via
REST
Java
Quick
Walkthrough
Python
Edit
application costs with
GraphQL
40. Embedding
GraphQL:
Editing
application
cost
in
Python
– Create
the
connection
40https://dev.leanix.net/v4.0/docs/graphql-‐example-‐application-‐costs
41. 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
42. 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
43. 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
support@leanix.net for
feedback,
questions
and
ideas
• Learn
how
to
upload
your
own
JavaScript
reports
based
on
GraphQL into
LeanIX
44. 44
“You
can’t
build
your
IT
architecture
today
with
yesterday’s
tools
and
stay
in
business
tomorrow”