Skip to content

fix: resolve NewType subtype_of matching for filter args#412

Merged
zachdaniel merged 1 commit intoash-project:mainfrom
nallwhy:fix/newtype-subtype-filter-operator-matching
Mar 5, 2026
Merged

fix: resolve NewType subtype_of matching for filter args#412
zachdaniel merged 1 commit intoash-project:mainfrom
nallwhy:fix/newtype-subtype-filter-operator-matching

Conversation

@nallwhy
Copy link
Copy Markdown
Contributor

@nallwhy nallwhy commented Mar 4, 2026

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
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

Summary

  • Fix do_get_expressable_types to check Ash.Type.NewType.subtype_of/1 base type when matching operator args, so operators expecting concrete types (e.g. [:string, :string]) work on NewType fields

Problem

When a field uses a NewType (e.g. subtype_of: :string), the GraphQL filter schema generation failed to match it against operator/function args like [:string, :string]. This caused predicate functions (e.g. Like) to be silently excluded from the generated filter input types, even when explicitly allowed via filterable_fields.

Solution

do_get_expressable_types now checks Ash.Type.NewType.subtype_of/1 to resolve the base type's short name when matching against operator args. For example, a NewType with subtype_of: :string will now also match operators that expect :string in their args.

Copilot AI review requested due to automatic review settings March 4, 2026 13:17
@nallwhy nallwhy force-pushed the fix/newtype-subtype-filter-operator-matching branch from a179e03 to a8a8749 Compare March 4, 2026 13:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes GraphQL filter schema generation so fields typed with Ash.Type.NewType can match predicate operator/function argument type specs based on their subtype_of base type (e.g. allowing [:string, :string] predicates on NewType-backed string fields).

Changes:

  • Update do_get_expressable_types/3 to consider a NewType’s subtype_of base type when matching operator/function arg type signatures.
  • Add a regression test and supporting test fixtures (custom predicate function, resource, and ETS data layer wrapper) to ensure NewType subtype matching includes the expected predicate.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/resource/resource.ex Extends expressable-type matching logic to consider NewType base type and tweaks warning string whitespace.
test/filter_sort_test.exs Adds regression coverage asserting ilike appears for a NewType-backed filter field.
test/support/test_ilike_function.ex Introduces a custom predicate function :ilike with [:string, :string] args for matching coverage.
test/support/resources/tag_with_ilike.ex Adds a resource with a NewType attribute and restricted filter operators including :ilike.
test/support/ets_with_functions.ex Adds an ETS-based data layer wrapper that exposes the custom function for tests.
test/support/domain.ex Registers the new test resource in the test domain.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zachdaniel zachdaniel merged commit ded9fab into ash-project:main Mar 5, 2026
22 of 23 checks passed
@zachdaniel
Copy link
Copy Markdown
Contributor

🚀 Thank you for your contribution! 🚀

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.

3 participants