Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Query Fields ("folders" to better organize related fields) #580

Open
stygmate opened this issue Jul 12, 2024 · 5 comments
Open

Nested Query Fields ("folders" to better organize related fields) #580

stygmate opened this issue Jul 12, 2024 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@stygmate
Copy link
Contributor

stygmate commented Jul 12, 2024

Is there a simple way to move fields that are in base Query Into subfields to namespace/organize them ?
(I keep running into issues. 😓)

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@bellini666
Copy link
Member

Can you give more information about this, with examples if possible?

@stygmate
Copy link
Contributor Author

stygmate commented Jul 13, 2024

@bellini666

with this query:

query MyQuery {
  param {
    equip {
      edges {
        node {
          id
        }
      }
    }
  }
}

this don't work:

@strawberry.type
class Param:
    equip: ListConnectionWithTotalCount[types_.Equip] = strawberry_django.connection()

@strawberry.type
class Query:
    param: Param = strawberry.field()

but this (with a custom resolver) work :

@strawberry.type
class Param:
    equip: ListConnectionWithTotalCount[types_.Equip] = strawberry_django.connection()

@strawberry.type
class Query:
    @strawberry.field()
    def param(self, info) -> Param:
        return Param(equip=types_.Equip.__strawberry_django_definition__.model.objects)

( i get the model manager from strawberry_django_definition 🤪 but i think you have it )

@bellini666 bellini666 added enhancement New feature or request question Further information is requested and removed enhancement New feature or request labels Jul 13, 2024
@bellini666
Copy link
Member

bellini666 commented Jul 13, 2024

Is Param a django type? In your example you wrote it as @strawberry.type, but if it is using @strawberry_django.type(ParamModel), then you can do:

@strawberry.type
class Query:
    param: Param = strawberry_django.field()
    # or if you are using relay and Param inherits from Node
    param: Param = strawberry_django.node()

Let me know if that works

@stygmate
Copy link
Contributor Author

stygmate commented Jul 14, 2024

@bellini666

No, Param is not a Django type, there's no django model named Param.
param field (using Param type) is meant to be a "folder" to better organize related fields of my api.

@bellini666 bellini666 added enhancement New feature or request help wanted Extra attention is needed and removed question Further information is requested labels Jul 14, 2024
@stygmate stygmate changed the title Nested Query Fields Nested Query Fields ("folders" to better organize related fields) Jul 14, 2024
@stygmate
Copy link
Contributor Author

@bellini666 i see that you have taged this "help wanted", I renamed this issue by adding ("folders" to better organize related fields) to make it more understandable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants