ash-project / ash-project/ash_graphql
if a resource's `type` is `subscription`, the generated schema conflicts with the subscription schema
- Dominant language
- Elixir
- Stars
- 97
- Forks
- 101
- Avg merge
- 12h 51m
- Merged PRs (30d)
- 5
Description
### Code of Conduct
- [x] I agree to follow this project's Code of Conduct
### AI Policy
- [x] I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.
### Versions
elixir 1.18.4
ash 3.6.2
ash_graphql 1.8.3
### Operating system
Linux docker container on macOS
### Current Behavior
I haven't verified all different potential iterations of this bug, but I have an application that does _not_ make use of graphql subscriptions. I recently added a resource modeling a "subscription" within my application, and named its graphql type `:subscription`. I noticed that in the generated graphql schema file, the schema now had a subscription key in the root schema, like this:
```graphql
schema {
mutation: RootMutationType
query: RootQueryType
subscription: Subscription
}
```
with `type Subscription` having my subscription resource's fields
where it had previously (and still does if I change the type name to anything other than `subscription`) looked like this:
```graphql
schema {
mutation: RootMutationType
query: RootQueryType
}
```
I assume this is because `Subscription` is effectively a reserved type name for graphql subscriptions. I'm not sure what would happen here if this occurred in an application that _did_ use graphql subscriptions, but I suspect these would overlap in a more catastrophic way (my application did still compile).
### Reproduction
- create a resource called `MyApp.Domain.Subscription` with any attributes
- it should use the `AshGraphql.Resource` extension, have a graphql `type` of `:subscription`, and wire up a query of some sort so it does show up in the schema file
- generate the sdl file
- see the behavior described
### Expected Behavior
I think the easiest way to avoid this would be to simply raise if a graphql type is called `subscription`, since that type name is effectively reserved by ash_graphql.
The name of the internal subscription type could also be made configurable, which would allow users to name a type `subscription` if they explicitly rename the internal subscription type.
Contributor guide
Research direction
The issue names no files or tests; reproduce it with a resource whose AshGraphql type is :subscription, then trace the generated SDL and the handling of the internal Subscription type. Done means a resource type named subscription no longer creates a conflicting root subscription schema, with behavior covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir, graphql
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100