Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Apidays Paris 2023 - GraphQL Nullability, State of the Union, Martin Bonnin, Apollo GraphQL

Apidays Paris 2023 - GraphQL Nullability, State of the Union, Martin Bonnin, Apollo GraphQL

Apidays Paris 2023 - Software and APIs for Smart, Sustainable and Sovereign Societies
December 6, 7 & 8, 2023

GraphQL Nullability, State of the Union
Martin Bonnin, Mobile Engineer at Apollo GraphQL

------

Check out our conferences at https://www.apidays.global/

Do you want to sponsor or talk at one of our conferences?
https://apidays.typeform.com/to/ILJeAaV8

Learn more on APIscene, the global media made by the community for the community:
https://www.apiscene.io

Explore the API ecosystem with the API Landscape:
https://apilandscape.apiscene.io/

apidays

December 18, 2023
Tweet

More Decks by apidays

Other Decks in Marketing & SEO

Transcript

  1. { "data" { "video": { "id": "42", "title": "GraphQL 101",

    "uploadDate": "2023-12-03T22:26:46Z" } } }
  2. Error null != Semantic null { "errors": [ { "message":

    "cannot resolve title", "path": "video.title" } ] "data": { "video": { "id": "42", "title": null } } }
  3. Terminology • Error null ◦ Exceptional case ◦ Has an

    error in the errors array • Semantic null ◦ Business case ◦ No error in the errors array
  4. Post mortem • New feature: video upload • During the

    upload, a video doesn’t have a title yet • This was a backward compatible schema change!
  5. @Composable fun VideoItem(response: Response) { if (response.errors.isNotEmpty()) { Error() }

    else { if (response.data.video.title == null) { Text(text = "This video doesn't have a title yet") } else { Text(text = response.data.video.title) } } }
  6. @Composable fun VideoItem(response: Response) { if (response.errors.any { it.path ==

    "video.title" }) { Error() // Can't display a video without a title } else { if (response.data.video.title != null) { Text(text = "This video does not have a title yet") } else { Text(text = response.data.video.title!!) } if (response.errors.any { it.path == "video.viewCount" }) { // Skip viewCount } else { Text(text = "${response.data.video.viewCount!!} + views") } } } Partial data
  7. GraphQL is missing types Your favorite type-safe language GraphQL string

    → String! string | null → String string | error → String string | null | error → String
  8. Documentation type Video { """ The title of the Video

    null if the video has just been uploaded """ title: String """ Number of times this video has been watched Never null unless there is an error """ viewCount: Int }
  9. Nullability working group 2021 Client Controlled Nullability May 2023 sub

    working group Sep 2023 GraphQL conf True nullability Asterisk Interrobang Oct 2023 semantic-non-null @strictNullability @catch graphql/nullability-wg
  10. Nullability working group 2021 Client Controlled Nullability May 2023 sub

    working group Sep 2023 GraphQL conf True nullability Asterisk Interrobang Oct 2023 semantic-non-null @strictNullability @catch graphql/nullability-wg
  11. Asterisk string → String! string | null → don’t use

    string | error → String* string | null | error → String graphql/graphql-spec/pull/1048 Never a semantic null
  12. Strict nullability string → String! string | null → don’t

    use string | error → String string | null | error → String? graphql/graphql-wg/discussions/1410 schema @strictNullability { query: Query } Never a semantic null
  13. Conclusion • null is not always what it seems! •

    be aware of the tradeoffs • document nullability • get involved!
  14. Input nullability string → String! string | null → String

    string | absent → String string | null | absent → String graphql/graphql-spec/issues/476
  15. Semantic non-null string → String! string | null → don’t

    use string | error → !String string | null | error → String graphql/graphql-spec/pull/1065
  16. Interrobang string → String! string | null → don’t use

    string | error → String!? string | null | error → String graphql/graphql-spec/pull/1046
  17. string → String! string | null → don’t use string

    | error → String @semanticNonNull string | null | error → String @semanticNonNull
  18. Problem 2: what default? • Fail the whole query ◦

    Easy ◦ Fragile • Handle field errors ◦ Hard ◦ Robust
  19. Opting in error handling • Start easy • Add error

    handling progressively fragment VideoDetails on Video { video { title # opt-in error handling viewCount @catch } } facebook/relay/issues/4416
  20. Opting in error handling fragment VideoDetails on Video { video

    { title # opt-in error handling viewCount @catch } } sealed interface Result<T> { class Success(val value: T): Result class Failure(val error: error): Result } Video( val title: String val viewCount: Result<Int> ) apollographql/apollo-kotlin/pull/5405
  21. Client Controlled Nullability graphql/graphql-wg/blob/main/rfcs/ClientControlledNullability.md fragment videoDetails on Video { video

    { # We need title to display a video title! # It's okay to fail viewCount viewCount? } }
  22. string → String string | null → String? string |

    error → String @throws string | null | error → String? @throws Exceptions graphql/nullability-wg/discussions/39
  23. Exceptions string → don’t use string | null → don’t

    use string | error → String string | null | error → String? graphql/nullability-wg/discussions/39
  24. Layouts How do I add a new slide with a

    preexisting layout? Layout Guidelines To add template to a blankslide, click on layout. Click on any template and start editing.
  25. Font & Sizes How do I edit text while keeping

    the same font style and size? Layout Guidelines Right click “Paste without formatting” Or select your text and click “Clear formatting”
  26. Add images How do I add a image container? Layout

    Guidelines Click on the picture icon to replace image Double Click to resize or adjust image placement Test it out here!
  27. Exploring what we learned from hundreds of organizations transforming their

    business and customer experiences with GraphQL Insights on the rise of GraphQL John Doe Engineer Katharina Wagner October 2023 Sunday palace Engineer
  28. Exploring what we learned from hundreds of organizations transforming their

    business and customer experiences with GraphQL Insights on the rise of GraphQL John Doe Engineer Katharina Wagner Engineer October 2023 on Sunday Palace
  29. “If a monolithic architecture is working for your company, then

    don't let us be the ones to convince you otherwise. If you are down this microservices road, then Federation is a really great option.” Meeng Chee CEO at Peloton Email or contact
  30. APIs fuel growth. They are a critical component of every

    digital initiative in the modern age. Modernization initiatives Developer velocity Omni-channel Mergers and acquisitions
  31. How do the developers that support these initiatives access all

    of these APIs? Products Images Deals Reviews Inventory Recommend ations
  32. • Self-service Teams can use them asynchronously. • Paved road

    A clear, proven path for teams to follow. • Time to value New users get great results quickly. • Coherence Teams can easily find what they need. • Cohesion Features build on each other. • Opinionated A platform cannot be one-size-fits all.
  33. A really long long subtitle with at least 3 lines

    of text. Item title Build variants of your graph for testing, staging, and production environments. Prevent breaking changes Ensure you can safely deliver changes across all clients using schema checks. Communicate cross-functionally Deliver notifications to systems and teams using webhooks. Title
  34. Safely ship changes to the graph with tools that integrate

    with your CI/CD pipeline. Test with ease Build variants of your graph for testing, staging, and production environments. Prevent breaking changes Ensure you can safely deliver changes across all clients using schema checks. Communicate cross-functionally Deliver notifications to systems and teams using webhooks. DELIVER