#extract #graphql #data #results #nested #type #node

macro graphql-extract

Macro to extract data from deeply nested types representing GraphQL results

4 releases

new 0.0.4 Feb 6, 2025
0.0.3 Feb 3, 2025
0.0.2 Jan 29, 2025
0.0.1 Jan 28, 2025

#84 in #results

Download history 37/week @ 2025-01-22 466/week @ 2025-01-29

503 downloads per month
Used in 4 crates (via sui-gql-client)

Apache-2.0

13KB
228 lines

Macro to extract data from deeply nested types representing GraphQL results

Suggested workflow

  1. Generate query types using cynic and its generator
  2. Use insta to define an inline snapshot test so that the query string is visible in the module that defines the query types
  3. Define an extract function that takes the root query type and returns the data of interest
  4. Inside extract, use extract! as extract!(data => { ... })
  5. Inside the curly braces, past the query string from the snapshot test above
  6. Change all node names from camelCase to snake_case
  7. Add ? after the nodes that are nullable
  8. Add [] after the nodes that are iterable

lib.rs:

Macro to extract data from deeply nested types representing GraphQL results

Suggested workflow

  1. Generate query types using cynic and its generator
  2. Use insta to define an inline snapshot test so that the query string is visible in the module that defines the query types
  3. Define an extract function that takes the root query type and returns the data of interest
  4. Inside extract, use extract! as extract!(data => { ... })
  5. Inside the curly braces, past the query string from the snapshot test above
  6. Change all node names from camelCase to snake_case
  7. Add ? after the nodes that are nullable
  8. Add [] after the nodes that are iterable

Dependencies

~215–660KB
~16K SLoC