graphql_rails icon indicating copy to clipboard operation
graphql_rails copied to clipboard

Inference based on conventions

Open chrisortman opened this issue 4 years ago • 3 comments

Hello. I can't quite tell if this library will infer any controller actions and model based on conventions or if I am supposed to always specify it.

resources :users

We could infer:

model('User')
action(:show).returns_single
action(:index).returns_list
action(:create).returns_single
action(:update).returns_single
action(:destroy).returns_single

I don't see these lines in the example, but they appear to be required?

chrisortman avatar Oct 17 '20 20:10 chrisortman

Please explain more what you are trying to achieve.

But basically, if I've correctly understood your question, when you add to graphql router resources :users graphql_rails expects that you have these actions (and methods which correspond to these actions) defined in your graphql rails controller (like in this example.

Also, a great code example about routes and resources actions handling is here.

pucinsk avatar Oct 17 '20 21:10 pucinsk

I think what confuses me is your first example UsersController does not

define index,show,create,update,delete actions

That led me to think those actions would automatically exist

On October 17, 2020, GitHub [email protected] wrote:

Please explain more what you are trying to achieve.

But basically, if I've correctly understood your question, when you add to graphql router resources :users graphql_rails expects that you

have these actions (and methods which correspond to these actions) defined in your graphql rails controller (like in this example https://github.com/samesystem/graphql_rails#define-controller.

Also, a great code example about routes and resources actions handling

is here https://github.com/samesystem/graphql_rails#routes.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <https://github.com/samesystem/graphql_rails/issues/163#issuecomment- 711083473>, or unsubscribe <https://github.com/notifications/unsubscribe- auth/AAAAXCVPL35VE6WZIEOE4BLSLIE7TANCNFSM4SUSVXEA>.

chrisortman avatar Oct 18 '20 12:10 chrisortman

Hey, @chrisortman. Sorry for the delayed response, but just to be short - defining a resource currently does not define actions in the controller itself, meaning you have to add them manually. However, you're correct on it sort of misleading you in the documentation/examples, and we'll update that soon. Leaving the issue as open before we do that.

jusmat avatar Dec 22 '20 10:12 jusmat