strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
https://strawberry.rocks/docs/django
MIT License
409 stars 118 forks source link

Implementation question: relay support including query term with dictionary argument #413

Closed danielmcquillen closed 10 months ago

danielmcquillen commented 11 months ago

Thanks for this great project.

I want to use it to add GraphQL support...but I need to support a graphQL query that implements a let's say someSpecificABCQuery query that has a shape like:

query{
  someSpecificABCQuery(
    where: {
      componentId: { equalTo: "1234-(some-long-uuid)-5678" }
    }
  ) {
    nodes {
      resourceTree {
        root {
          value {
            locator
          }
        }
      }
    }
  }
}

and at the moment I can't figure out if I can support this structure (that enclose the 'where' clause with "equalTo" term in parenthesis) or not using strawberry-graphql-django.

Unfortunately this format can't be changed...although I wish it could as, from what I understand, GraphQL best practices have evolved, could be much simpler.

Is it impossible to support this particular format, with the where dictionary as an argument to the query, using strawberry-graphql?

(Sorry for posting basic question here...if there's a forum or other gathering place please let me know... happy to move this question there.)

Upvote & Fund

Fund with Polar

bellini666 commented 11 months ago

Hi @danielmcquillen ,

Yes it is possible. You probably want to use something like this:

@strawberry.input
class ComponentIdInput:
    equal_to: str

@strawberry.input
class WhereInput:
    component_id: ComponentIdInput

@strawberry.type
class Query:
    @strawberry.field
    def some_specific_ABC_query(self, where: WhereInput) -> ABCType:
        # access it with where.component_id.equal_to
        ...

(Sorry for posting basic question here...if there's a forum or other gathering place please let me know... happy to move this question there.)

Np! :)

But yeah, we have a forum at discord for questions like this: https://strawberry.rocks/discord

danielmcquillen commented 10 months ago

@bellini666 Thanks for the info!