strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations 🍓
https://strawberry.rocks
MIT License
3.87k stars 511 forks source link

Ability to change StrawberryConfig's relay_max_results value #3284

Open sunweiyang opened 7 months ago

sunweiyang commented 7 months ago

Right now the only thing that can be changed in schema configs is auto_camel_case: https://strawberry.rocks/docs/types/schema-configurations

It would be useful to similarly be able to set relay_max_results as follows, which is not possible right now:

import strawberry

from strawberry.schema.config import StrawberryConfig

@strawberry.type
class Query:
    example_field: str

schema = strawberry.Schema(query=Query, config=StrawberryConfig(relay_max_results=1000))

In the meantime, I need a workaround; my app needs a higher relay_max_results than the default 100. How can I accomplish this?

Upvote & Fund

Fund with Polar

pcraciunoiu commented 5 months ago

If anyone else stumbles on this, I was able to work around it like so.

from dataclasses import dataclass

from strawberry.schema.config import StrawberryConfig

@dataclass
class CustomStrawberryConfig(StrawberryConfig):
    def __post_init__(self, auto_camel_case: bool):
        # for some reason, defining this at the class-level does not work
        self.relay_max_results = 200
        return super().__post_init__(auto_camel_case)

schema = strawberry.Schema(
    query=Queries, mutation=Mutations, config=CustomStrawberryConfig()
)