|
| 1 | +# SPDX-FileCopyrightText: 2020 ash_graphql contributors <https://github.com/ash-project/ash_graphql/graphs/contributors> |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +defmodule AshGraphql.MissingRelatedDomainTest do |
| 6 | + use ExUnit.Case, async: false |
| 7 | + |
| 8 | + # Define ResourceB and DomainB as valid, fully-compiled modules outside of the test. |
| 9 | + # The test scenario is: both domains are valid, but the schema only registers DomainA. |
| 10 | + |
| 11 | + alias AshGraphql.MissingRelatedDomainTest.{ |
| 12 | + RelatedDomain, |
| 13 | + SourceDomain, |
| 14 | + RelatedResource, |
| 15 | + SourceResource |
| 16 | + } |
| 17 | + |
| 18 | + defmodule RelatedResource do |
| 19 | + use Ash.Resource, |
| 20 | + domain: RelatedDomain, |
| 21 | + extensions: [AshGraphql.Resource] |
| 22 | + |
| 23 | + graphql do |
| 24 | + type :missing_test_related_resource |
| 25 | + end |
| 26 | + |
| 27 | + actions do |
| 28 | + default_accept(:*) |
| 29 | + defaults([:read]) |
| 30 | + end |
| 31 | + |
| 32 | + attributes do |
| 33 | + uuid_primary_key(:id) |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + defmodule RelatedDomain do |
| 38 | + use Ash.Domain, extensions: [AshGraphql.Domain] |
| 39 | + |
| 40 | + resources do |
| 41 | + resource(RelatedResource) |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + defmodule SourceResource do |
| 46 | + use Ash.Resource, |
| 47 | + domain: SourceDomain, |
| 48 | + extensions: [AshGraphql.Resource] |
| 49 | + |
| 50 | + graphql do |
| 51 | + type :missing_test_source_resource |
| 52 | + |
| 53 | + queries do |
| 54 | + list :list_source_resources, :read |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + actions do |
| 59 | + default_accept(:*) |
| 60 | + defaults([:read]) |
| 61 | + end |
| 62 | + |
| 63 | + attributes do |
| 64 | + uuid_primary_key(:id) |
| 65 | + end |
| 66 | + |
| 67 | + relationships do |
| 68 | + belongs_to(:related, RelatedResource, public?: true) |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + defmodule SourceDomain do |
| 73 | + use Ash.Domain, extensions: [AshGraphql.Domain] |
| 74 | + |
| 75 | + resources do |
| 76 | + resource(SourceResource) |
| 77 | + end |
| 78 | + end |
| 79 | + |
| 80 | + test "raises at compile time when a related resource's domain is not in the schema" do |
| 81 | + assert_raise RuntimeError, ~r/RelatedDomain/, fn -> |
| 82 | + defmodule TestSchemaMissingDomain do |
| 83 | + use Absinthe.Schema |
| 84 | + |
| 85 | + # Only SourceDomain is registered — RelatedDomain is intentionally omitted |
| 86 | + @domains [SourceDomain] |
| 87 | + use AshGraphql, domains: @domains |
| 88 | + end |
| 89 | + end |
| 90 | + end |
| 91 | +end |
0 commit comments