HackSoftware / Django-Styleguide

Django styleguide used in HackSoft projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How would graphql API fit in?

hgylfason opened this issue · comments

commented

I watched @RadoRado presentation about Django Structure from EuroPython Conference 2018 and found it very interesting.
His talk centered around Django structure with an REST API but I was wondering if you have used graphql inside this structure? If not, could you provide some insight on how you would fit it in?

@hgylfason That's a very good question. We don't have any big GraphQL project yet, but we plan on doing some internal testing so we can see how this approach is going to fit.

My "shot in the dark" is to use the services and selectors in your resolves. Just don't let the GraphQL library add abstraction around your models, just like the generic views from DRF or Django.

But once we get more experience, we'll definitely add it here.

I'm closing this for now, if we have any GraphQL input, we'll be updating that 🙌

Hey @RadoRado just wanted to ask if you've evolved your thinking around GraphQL for this style guide.

We're building both a REST and GraphQL API for our new platform and have been using this style guide religiously for REST but we're not too sure how graph will fit into it.

@kareemcoding Hello 👋

We haven't got the change to really test GraphQL in a production app, so keep that in mind.

My take would be:

  1. For selectors, as far as I understand, the control is on the frontend for what to include. What you can do is to define a custom query type, which only has one field called data (for example) and then define a custom resolve to fetch whatever you need. Of course, this goes against the nature of GraphQL, where what you need is in control of the caller, rather than the backend.
  2. For services, I see there's a nice way to hook into a mutation, where you get your data parsed & you have full control. You can safely call your service layer there. You can also go on & use DRF's serializes, as far as I can see - https://docs.graphene-python.org/projects/django/en/latest/mutations/#django-rest-framework

That's my take.

For me, GraphQL is just a different way of communicating between the client & the APIs, but everything else stays the same.

Cheers ✌️

hey @kareemcoding can you say about result of using Django-Styleguide in GraphQL in production? it is really fit?