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

Returning a Query type in a mutation's payload #655

Open
rcybulski1122012 opened this issue Nov 8, 2024 · 0 comments
Open

Returning a Query type in a mutation's payload #655

rcybulski1122012 opened this issue Nov 8, 2024 · 0 comments

Comments

@rcybulski1122012
Copy link

rcybulski1122012 commented Nov 8, 2024

I have a Query type in my schema that defines some custom resolvers and uses strawberry_django.field/strawberry_django.node without providing resolver functions.

@strawberry_django.type(SomeModel)
class SomeType:
    id: auto
    name: auto


@strawberry.type(name='Query')
class Query:
    some_type_query: SomeType = strawberry_django.field()

    @strawberry_django.field()
    def custom_resolver(self) -> bool:
        return True

I want to return a Query along with the mutation result, enabling the user to fetch whatever data they need in a single request. However, when I initialize a Query object, I must provide arguments.

@strawberry.type
class MutationPayload:
    some_type: SomeType

    @strawberry_django.field(
    def query(self) -> Query:
        return Query()


@strawberry.type
class Mutation:
    @strawberry_django.mutation()
    def mutation_resolver(self) -> MutationPayload:
        some_model = SomeModel.objects.create(name="test")
        return MutationPayload(some_type=some_model)
{
  "data": null,
  "errors": [
    {
      "message": "Query.__init__() missing 1 required keyword-only argument: 'some_type_query'",
      "locations": [
        {
          "line": 7,
          "column": 5
        }
      ],
      "path": [
        "mutationResolver",
        "query"
      ]
    }
  ]
}

Is it possible to initialize the Query type without providing all the arguments? Or is there an easy way to provide the arguments to the query?

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant