Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce filtering, ordering and pagination to graphql api #308

Merged
merged 66 commits into from
Mar 28, 2023

Conversation

sandreae
Copy link
Member

@sandreae sandreae commented Mar 21, 2023

This PR introduces the ability to pass arguments for filtering, ordering and paginating collection queries and parses these arguments into our own types with validation.

draft api ideas:
https://laub.liebechaos.org/ZDW0yABySHSkc2aeG_ctWQ?view
https://laub.liebechaos.org/fplolxRFSvumhEzgdYSxiQ

  • filtering
    • static filter objects for all operation value types
    • dynamically build filter input object per schema
    • accept these arguments in all_x queries
    • accept these arguments in single document query (i don't think we want this)
    • filter by meta fields
    • parse abstract filter from field filter arguments
    • parse abstract filter from meta filter arguments
  • pagination
    • accept all arguments for performing cursor based pagination in all_x queries
    • query for documents at root of collection query and pass the values up to children
    • introduce pagination response wrapper type
    • parse abstract query struct
  • ordering
    • static order direction type for ASC & DESC
    • dynamically build enum of possible orderBy options
    • accept these arguments in all_x queries
    • order by meta fields
    • parse abstract query
  • all of the above for relation lists
  • docs and descriptions for all new types / methods / arguments

Query a collection with pagination, ordering and filtering:

{
  all_event_0020c3560ffcfa50f14ab01740cd8f832e0fb35035eeb8cd4aca124bac2d42a47a2a(
    after: "0_00205406410aefce40c5cbbb04488f50714b7d5657b9f17eed7358da35379bc20331" 
    first: 10
    orderBy: OWNER
    orderDirection: ASC
    filter: {
      date: {
        gt: "01-12-2012"
        lt: "01-12-2022"
        notIn: ["01-02-2016", "01-02-2017"]
        notEq: "01-02-2018"
      }
      band: {
        eq: "00205406410aefce40c5cbbb04488f50714b7d5657b9f17eed7358da35379bc20331"
      }
      description: {
        contains: "panda is cool"
      }
    }
    meta: {
      owner: {
        in: ["7cf4f58a2d89e93313f2de99604a814ecea9800cf217b140e9c3a7ba59a5d982"]
      }
      edited: {
        eq: true
      }
      documentId : {
        in: ["00205406410aefce40c5cbbb04488f50714b7d5657b9f17eed7358da35379bc20331"]
      }
      viewId : {
        notIn: ["00205406410aefce40c5cbbb04488f50714b7d5657b9f17eed7358da35379bc20331"]
      }
    }
  ) {
    document {
      fields {
        band {
          fields {
            name
          }
        }
      }
    }
  }
}

Query a relation list on a document with pagination, ordering and filtering:

{
  all_schema_definition_v1 {
    document {
      fields {
        name
        fields(
          after: "0_002099dd2c7a77ce59fddb48bcfd18baefc73888849436d471d4aba40aa8f027e13a"
          first: 50
          orderBy: name
          orderDirection: ASC
          filter: { name: { eq: "hello" } }
        ) {
          totalCount
          document {
            meta {
              documentId
            }
          }
        }
      }
    }
  }
}

NEXT:

  • implement filter nesting for relation fields (to a max depth)

📋 Checklist

  • Add tests that cover your changes
  • Add this PR to the Unreleased section in CHANGELOG.md
  • Link this PR to any issues it closes
  • New files contain a SPDX license header

@codecov
Copy link

codecov bot commented Mar 21, 2023

Codecov Report

Patch coverage: 85.62% and project coverage change: -0.37 ⚠️

Comparison is base (0dfddcd) 90.29% compared to head (6a16935) 89.92%.

❗ Current head 6a16935 differs from pull request most recent head b524333. Consider uploading reports for the commit b524333 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #308      +/-   ##
==========================================
- Coverage   90.29%   89.92%   -0.37%     
==========================================
  Files          62       66       +4     
  Lines        4524     4945     +421     
==========================================
+ Hits         4085     4447     +362     
- Misses        439      498      +59     
Impacted Files Coverage Δ
...quadoggo/src/graphql/scalars/document_id_scalar.rs 78.57% <ø> (ø)
...ggo/src/graphql/scalars/document_view_id_scalar.rs 92.85% <ø> (ø)
aquadoggo/src/graphql/tests.rs 100.00% <ø> (ø)
aquadoggo/src/lib.rs 100.00% <ø> (ø)
aquadoggo/src/graphql/scalars/cursor_scalar.rs 47.36% <47.36%> (ø)
aquadoggo/src/graphql/utils.rs 68.18% <65.38%> (-25.57%) ⬇️
aquadoggo/src/graphql/types/paginated_response.rs 92.85% <92.85%> (ø)
aquadoggo/src/graphql/types/document_fields.rs 96.26% <95.50%> (-3.74%) ⬇️
aquadoggo/src/graphql/types/document.rs 96.96% <96.42%> (-3.04%) ⬇️
aquadoggo/src/graphql/queries/all_documents.rs 100.00% <100.00%> (ø)
... and 6 more

... and 5 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@sandreae sandreae changed the base branch from reorganise-graphql-modules to main March 21, 2023 14:39
@sandreae sandreae changed the title Introduce Filter and StringFilter inputs Introduce filtering by field to graphql api Mar 21, 2023
@sandreae sandreae changed the title Introduce filtering by field to graphql api Introduce filtering by field values to graphql api Mar 21, 2023
@sandreae sandreae changed the title Introduce filtering by field values to graphql api Introduce filtering, ordering and pagination to graphql api Mar 23, 2023
@sandreae sandreae marked this pull request as ready for review March 28, 2023 12:09
@sandreae
Copy link
Member Author

Finally ready for review @adzialocha !!

@cafca wanted to ping you too as thought you might be interested to see this PR ;-p

Copy link
Member

@adzialocha adzialocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤩✨

aquadoggo/src/graphql/queries/all_documents.rs Outdated Show resolved Hide resolved

// Pass them up to the children query fields.
Ok(Some(FieldValue::owned_any(args)))
// Get the whole document from the store.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, this means we only do one database request now and populate the data to the children? That's great!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, pretty much! In the case of collection queries, it's actually one db query per paginated query though. So for relation lists, a new query will be made.

aquadoggo/src/graphql/queries/document.rs Outdated Show resolved Hide resolved
aquadoggo/src/graphql/types/filter_input.rs Outdated Show resolved Hide resolved
aquadoggo/src/graphql/types/filters.rs Outdated Show resolved Hide resolved
aquadoggo/src/graphql/types/filters.rs Show resolved Hide resolved
aquadoggo/src/graphql/types/next_arguments.rs Outdated Show resolved Hide resolved
aquadoggo/src/graphql/types/ordering.rs Outdated Show resolved Hide resolved
@adzialocha adzialocha merged commit 57cdc6e into main Mar 28, 2023
@adzialocha adzialocha mentioned this pull request Apr 10, 2023
14 tasks
@adzialocha adzialocha deleted the graphql-query-api branch April 18, 2023 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants