Skip to content

Support field?: false calculations in GraphQL schema#446

Open
jaylynntautu wants to merge 3 commits into
ash-project:mainfrom
jaylynntautu:support-calculation-field-false
Open

Support field?: false calculations in GraphQL schema#446
jaylynntautu wants to merge 3 commits into
ash-project:mainfrom
jaylynntautu:support-calculation-field-false

Conversation

@jaylynntautu

Copy link
Copy Markdown
Contributor

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • [X ] Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

Summary

This updates GraphQL response schema generation to respect Ash calculations using field?: false.

Calculations marked with field?: false are now excluded from normal GraphQL response fields while still remaining available in filter and sort schema generation.

Changes

  • Updated calculations/3 in lib/resource/resource.ex to exclude calculations where field? is false

  • Replaced the old read test that allowed querying nonFieldCalc

  • Added regression tests confirming:

    • field?: false calculations are not exposed on the Post response type
    • field?: false calculations are still included in PostFilterInput
    • field?: false calculations are still included in PostSortField

Verification

Ran locally:

  • mix test
  • mix format --check-formatted
  • mix credo --strict

Full test suite passing locally:

  • 370 tests
  • 0 failures

@zachdaniel

Copy link
Copy Markdown
Contributor

So we actually can support these as fields in GraphQL, they just have to be picked from record.calculations[name] if loaded.

@zachdaniel

Copy link
Copy Markdown
Contributor

Maybe we should make that opt-in somehow though 🤔

@jaylynntautu

Copy link
Copy Markdown
Contributor Author

Ohhh okay I followed the original issue description and excluded them from the response schema while keeping filter/sort support. Since they can still be resolved through record.calculations[name], would you like me to update this PR in that direction instead?

@zachdaniel

Copy link
Copy Markdown
Contributor

Yes please 🙇

@zachdaniel

Copy link
Copy Markdown
Contributor

Although, I think what we should do is hide them from the GraphQL by default and add a new DSL option to include them. Like include_non_field_calculations: [:foo, :bar]

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.

2 participants