ash-project / ash_graphql

The extension for building GraphQL APIs with Ash
https://hexdocs.pm/ash_graphql
MIT License
73 stars 49 forks source link

Type should be optional for resources that only expose generic actions #119

Closed rbino closed 7 months ago

rbino commented 7 months ago

Is your feature request related to a problem? Please describe. I am working on a resource that only needs to expose a single generic action. In that case, since the resource itself is never exposed in GraphQL, the type option is actually not needed, but AshGraphql requires me to provide one.

Describe the solution you'd like To avoid breaking compatiblity and ensure that the choice is informed I think there should be an additional option (e.g. generate_type? false) and either type or generate_type? false has to be provided.

Alternatively, type could be enforced only for resources that expose some non-generic action.

Describe alternatives you've considered The main alternative right now is moving the generic action in another resource that already has a connected type.

Express the feature either with a change to resource syntax, or with a change to the resource interface

  graphql do
    generate_type? false
  end
zachdaniel commented 7 months ago

We currently have the option: generate_object? which does this, but it doesn't make type optional. It would make sense for us to only require it if the type is necessary. generate_object? should be reserved for "I need an object type but I want to define it msyelf"

rbino commented 7 months ago

Right, generate_type? expresses the wrong idea. Alternative proposals: object_type? false, without_object? true, actions_only? true, generic_only? true.

Let me know what you think it's best (or if you have better suggestions), then I can try to take a stab at this

zachdaniel commented 7 months ago

Even though generate_object? is not the best name, I think it does everything we want it to currently. The main thing is just not to require type if we don't have to. I think it's safe to do that, and won't constitute a breaking change as long as we only skip generating the type in the appropriate cases. The reason for this is that absinthe already prunes unused types, so those users already wouldn't have seen said type in their schema.

So what really needs to happen is something like this:

  1. make type optional
  2. when generating the graphql schema, if we need to define a type for a resource and the resource doesn't have a configured type or generate_object? is not false, then we raise an error there telling them that we require a type.