Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

GraphQL-ify your APIs

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Wird geladen in …3
×

Hier ansehen

1 von 29 Anzeige

GraphQL-ify your APIs

Herunterladen, um offline zu lesen

GraphQL is query language for APIs, but what are the advantages and how would one implement such in their microservices/APIs. In this session, I will go through the basics of GraphQL, different aspects of GraphQL and architecture of such APIs. There will be a demo/live-coding on, how 3 different ways we can implement GraphQL for a Springboot microservice/API. Lots of examples, live coding and helpful comparison on structure, usage and implementations of GraphQL in Springboot & Java world.

GraphQL is query language for APIs, but what are the advantages and how would one implement such in their microservices/APIs. In this session, I will go through the basics of GraphQL, different aspects of GraphQL and architecture of such APIs. There will be a demo/live-coding on, how 3 different ways we can implement GraphQL for a Springboot microservice/API. Lots of examples, live coding and helpful comparison on structure, usage and implementations of GraphQL in Springboot & Java world.

Anzeige
Anzeige

Weitere Verwandte Inhalte

Diashows für Sie (20)

Ähnlich wie GraphQL-ify your APIs (20)

Anzeige

Aktuellste (20)

Anzeige

GraphQL-ify your APIs

  1. 1. GraphQL-ify your APIs Soham Dasgupta Solution Architect, Geek, Speaker, Blogger #teqnation2021
  2. 2. Soham Dasgupta • Father, Husband and Football lover • Capgemini Netherlands • Oracle ACE Associate • Tech Enthusiast/Programmer/Architect • Speaker & Blogger • Twitter : @iamsoham • LinkedIn: dasguptasoham • Github: sohamda • Medium: @iam.soham
  3. 3. What’s in store today GraphQL What Queries & Mutation Schemas & Types Show me some code graphql-java graphql-java-kickstart graphql-dgs-framework What’s better Implementation easiness – code, generation, error handling, testing, clients N+1 problem Memory footprint
  4. 4. • GraphQL is a query language for your API, and a server-side runtime for executing queries. • Backed by your existing code and data. • It was designed by Facebook to get around common constraints in fetching data via REST. • It was open sourced by Facebook in 2015. • Nothing to do with Graph DB. • Not a replacement of REST. • Not going to magically solve every API design issues.
  5. 5. Schema Query Results GraphQL provides description of the data in your API, gives clients the power to ask for exactly what they need.
  6. 6. https://landscape.graphql.org/card-mode?category=graph-ql-adopter&grouping=category&style=borderless Who is using it ?
  7. 7. GraphQL vs REST API vs SOAP https://trends.google.com/trends/explore?date=2018-07-04%202021-05-07&q=%2Fg%2F11cn3w0w9t,REST%20API,%2Fm%2F077dn
  8. 8. Hierarchical & Aggregator Strongly Typed Validation & Type check out- of-the-box API evolution without versioning GraphQL Characteristics
  9. 9. Query & Mutation • Ask what you need. • Expand the same query. • Send arguments. • Use Aliases, Fragment Schemas & Types • GraphQL schema language - allows us to talk about GraphQL schemas in a language-agnostic way. • Scalar : Int, String, Boolean, ID, Float • Lists & Non-Null • Union, Interfaces, Input Types
  10. 10. N+1 queries Caching complexity Community presence File Upload GraphQL Maturity
  11. 11. Show me some code graphql-java graphql-java-kickstart graphql-dgs-framework
  12. 12. demo-springboot-application H2 Providers(1) Services(*) JPA Repository Service /services (POST GET) Controller /services/{id} GET /providers (POST GET) /providers/{id} (GET) https://github.com/sohamda/serivce-repository-swagger /providerservice/{id} (GET)
  13. 13. graphql-java https://www.graphql-java.com/documentation/v16/ https://github.com/graphql-java Version 16.2 : Last updated on Feb’21
  14. 14. springboot-application-structure H2 Providers(1) Services(*) JPA Repository Service graphql-java DataFetcher DataLoader RuntimeWiri ng DataRegistry GraphQLSchema /graphql/providerservice https://github.com/sohamda/graphql-java
  15. 15. graphql-java- kickstart https://graphql-java-kickstart.com/ https://github.com/graphql-java-kickstart Version 11 : Last updated on Jan’21
  16. 16. springboot-application-structure H2 Providers(1) Services(*) JPA Repository Service graphql-java-kickstart Resolvers (Query, Mutation, Field GraphQLServlet ContextBuilder DataRegistry /graphql/providerservice https://github.com/sohamda/graphql-java-kickstart
  17. 17. dgs-framework https://netflix.github.io/dgs/ https://github.com/Netflix/dgs-framework Version 3.11 : Last updated on April’21
  18. 18. springboot-application-structure H2 Providers(1) Services(*) JPA Repository Service graphql-dgs DgsDataLoader DgsData /graphql/providerservice https://github.com/sohamda/graphql-dgs-netflix
  19. 19. What’s better Implementation easiness – code, generation, error handling, testing, clients N+1 problem Memory footprint
  20. 20. DataFetchers graphql-java Piece of code that fetches the data graphql-java-kickstart dgs 1. Define a @Component which defines datafetching methods. 2. Register them in while building/parsing the schema 1. Define @Component which implements GraphQLQueryResolver. 2. For field-level define a @Component which implements GraphQLResolver<T>. 1. Define a @DgsComponent. 2. Map the schema operations with @DgsData
  21. 21. DataLoaders graphql-java Piece of code that is responsible for N+1 query issue graphql-java-kickstart dgs 1. Define a BatchLoader which return s a CompletableFuture. 2. Define a DataLoaderRegistry @Bean which registers the Loader. 3. Define a DataFetcher using that Loader. 1. Define @Component which defines a loader and adds it to the registry. 2. Define a @Component which implements GraphQLServletContextBuilder and associate the registry. 1. Define a @DgsDataLoader. 2. Map the schema operations with @DgsData
  22. 22. Mutations graphql-java Piece of code that persist the data graphql-java-kickstart dgs 1. Define a @Component which defines datafetching methods. 2. Register them in while building/parsing the schema • Define @Component which implements GraphQLMutationResolver. 1. Define a @DgsComponent. 2. Map the schema operations with @DgsData
  23. 23. Error Handling graphql-java Piece of code that handles exceptions/errors graphql-java-kickstart dgs Implement GraphQLError 1. Enable ExceptionHandler property and handle them in a Spring way. 2. Implement GraphQLErrorHandler and manage the errors in overridden method. Define a @Component which implements DataFetcherExceptionHandler
  24. 24. Client graphql-java How to call a GraphQL API graphql-java-kickstart dgs 1. No defined way. 2. Needs text templates to generate requests. 1. Gives a Webclient library. 2. Needs text templates to generate requests. 1. GraphQLClient uses String as query which is same as the previous two. 2. Code generation using Gradle. This is the type-safe option.
  25. 25. Testing graphql-java How to test your code graphql-java-kickstart dgs 1. No defined way. 2. Only can test the service-repo layer. 1. No defined way. 2. Only can test the service-repo layer. 1. Code generation using Gradle. This is the type-safe option. 2. Use the generated classes to build request and test using DgsAutoConfiguration class. graphql-java graphql-java-kickstart dgs 1. No defined way. 1. No defined way. 1. Code generation using Gradle. 2. No maven option yet. Code Generation
  26. 26. Runtime memory & Image Size
  27. 27. Final Words graphql-java graphql-java-kickstart dgs • Solid base. Evolved and Matured. • A lot of Boilerplate code. • Need extra lib to work in Springboot • Not a easy way to UT everything you write. • No Clients avaiable. • Looks matured but missing extended documentation. • Still a bit of Boilerplate code. • Directly usable within Springboot. Although other modules available to work on Java only environments. • Not a easy way to UT everything you write. • Basic Client avaiable. • Not sure about maturity, but Netflix is behind this, so faith is there. • No Boilerplate code. • Directly usable within Springboot. • You can UT everything you write. • Client avaiable. • Code generation in gradle, but you get Java.
  28. 28. https://www.meetup.com/bld-tech-talks/
  29. 29. #teqnation2021 Thanks for your attention!

Hinweis der Redaktion

  • Who coded graphQL
  • Some people call them resolvers as well.
  • Or MapLoader. : is
  • Some people call them resolvers as well.
  • Or MapLoader. : is
  • Or MapLoader. : is
  • Or MapLoader. : is
  • Or MapLoader. : is
  • Or MapLoader. : is

×