At the CodeTalks conference 2017 in Hamburg, LeanIX presented their lessons learned for GraphQL, a new alternative for building REST APIs which was introduced by Facebook.
5. 5
• Shorter time to market
• Real-time big data insights
• Efficient scalability
• Exceptional user experience
• Consistent channels
• Integrated workflows
• …
More
• APIs
• Devices
• Sensors
IT Architectures are more important than ever before
14. Why GraphQL?
14
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
15. Why GraphQL?
15
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
16. Why GraphQL?
16
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
17. Why GraphQL?
17
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
18. Why GraphQL?
18
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
query {
id name type release
alias description
...on Application {
lifecycles {}
relToSuccessor {}
relToPredecessor {}
relToBusinessCapability {}
relToUserGroups {}
[...]
}
}
20. Why GraphQL?
20
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
query {
id name
}
query {
id name alias
}
query {
id name description
}
37. What about the Apollo Client?
37
• Apollo Client available here:
https://github.com/apollographql/apollo-client
• “A fully-featured, production ready caching GraphQL client for every
server or UI framework”
• Deep integration possible with React, Angular, iOS, Android, …
39. So, what about it then?
39
• Did you use it?
• No, it was not available when we started …
• Would you use it?
• Perhaps - it offers some nice abstractions (queries can be restarted
for instance), but our own very simplistic approach works very well
at the moment
44. What is the N + 1 Select Issue?
44
Application application = appDAO.getApplication();
for(Successor successor: application.getSucessors()) {
System.out.println(“Successor:“ + successor.getName());
}
Application application = appDAO.getApplication();
for(Successor successor: application.getSucessors()) {
System.out.println(“Successor:“ + successor.getName());
}
SELECT * FROM application WHERE ...SELECT * FROM application WHERE ...
SELECT * FROM successor WHERE id = successor.id;
SELECT * FROM successor WHERE id = successor.id;
SELECT * FROM successor WHERE id = successor.id;
...
# Selects
1
N
+
SELECT * FROM successor WHERE id = successor.id;
SELECT * FROM successor WHERE id = successor.id;
SELECT * FROM successor WHERE id = successor.id;
...
45. Why do we have this issue with GraphQL?
45
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
46. Why do we have this issue with GraphQL?
46
• Java Library uses Datafetcher
• Is a function to connect GraphQL to underlying DB
• Knows only his level
47. Why do we have this issue with GraphQL?
47
Application {
id
name
type
release
alias
description
Lifecycles {...}
Relations {
Successors
Predecessors
Business Capabilities
User Groups
[...]
}
[...]
}
id
name
type
release
alias
description
Lifecycles
Relations
id
name
type
release
alias
description
Lifecycles
Relations
48. Why do we have this issue with GraphQL?
48
• No context awareness
• No easy implementation due to „everything is a graph“
• Needs manual implementation to fix.
49. How To Solve This
49
• Prediction Library (enable context awareness)
• Batching
• Caching
• Facebooks solution is called relay
51. Exception Handling
51
• Exceptions of Java GraphQL Library are useless
• “An error occurred“
• You need context information to show usefull exceptions
• We implemented our own handler for that