Skip to content

feat: raise at compile time when related resource's domain is missing from schema#414

Merged
zachdaniel merged 1 commit intoash-project:mainfrom
nallwhy:feat/compile-time-missing-domain-check
Mar 5, 2026
Merged

feat: raise at compile time when related resource's domain is missing from schema#414
zachdaniel merged 1 commit intoash-project:mainfrom
nallwhy:feat/compile-time-missing-domain-check

Conversation

@nallwhy
Copy link
Copy Markdown
Contributor

@nallwhy nallwhy commented Mar 5, 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

Closes #41

When a resource has a relationship to another resource whose domain is not included in the schema, AshGraphql now raises a compile-time error with a clear, actionable message — instead of silently generating a broken schema that fails at runtime with an obscure Absinthe type error.

Error message example

SourceResource has a relationship `related` to RelatedResource,
but RelatedResource's domain is not included in this schema.

Add RelatedDomain to your schema's domain list:

    use AshGraphql, domains: [SourceDomain, RelatedDomain]

Changes

  • Added validate_domains_for_relationships!/2, called during use AshGraphql after all resources are collected. Checks each resource's public relationships — if the destination has the AshGraphql.Resource extension but its domain isn't in the schema, raises with instructions to fix.

Copilot AI review requested due to automatic review settings March 5, 2026 08:25
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

This PR adds a compile-time validation that detects when a resource has a relationship to another resource whose domain is not included in the AshGraphql schema's domain list. Instead of silently generating a broken schema that fails at runtime with an obscure Absinthe type error, users now get a clear, actionable error message at compile time. This closes issue #41.

Changes:

  • Added validate_domains_for_relationships!/2 function in AshGraphql that checks each resource's public relationships and raises if the destination resource has the AshGraphql.Resource extension but its domain is not registered in the schema.
  • Integrated the validation call during use AshGraphql after all resources are collected.
  • Added a test that verifies a RuntimeError is raised when a related resource's domain is missing from the schema.

Reviewed changes

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

File Description
lib/ash_graphql.ex Adds the validate_domains_for_relationships!/2 function and calls it during schema compilation to catch missing domains early.
test/missing_related_domain_test.exs New test file verifying that a compile-time error is raised when a related resource's domain is omitted from the schema.

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

@nallwhy nallwhy force-pushed the feat/compile-time-missing-domain-check branch from e5ea822 to 70f35b8 Compare March 5, 2026 08:41
@nallwhy nallwhy force-pushed the feat/compile-time-missing-domain-check branch from 70f35b8 to e6144e0 Compare March 5, 2026 13:46
@zachdaniel zachdaniel merged commit 0f4d890 into ash-project:main Mar 5, 2026
22 of 23 checks passed
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.

Catch if there are any apis missing from schema at compile time and provide instructions to add them to the list

3 participants