Comments (3)
This isn't really possible to do using a class decorator, since customizing the repr
for a type involves metaclasses and you can't change that after the type has been created. There's a few alternatives here:
- Introduce a metaclass + base class instead of the
strawberry.type
decorator, which would let you do this. Changes how you use the library, diverges from how you expect dataclasses to work, probably not worth it. - Use dataclasses' default repr behavior, and add a repr to the actual GraphQL type, i.e.
repr(Example.field)
. Requires either monkeypatching or extendinggraphql
types, or upstreaming this behavior to graphql-core-next. - Remove all custom
repr
behavior.
I'd personally lean towards #3, or maybe #2 if upstream would be interested in changing __repr__
on types.
from strawberry.
We could have a custom print that works with our types, I don't think graphql-core will want to change behaviours :)
So I'd do 3 plus a utility function that knows how to print our types. I think in future we will probably customise the printer anyway (to support schema directives), so I think it is fine using a custom function :)
from strawberry.
I've found a way to do this, but is not that nice: https://stackoverflow.com/a/56123966, but for now I'll remove the custom repr :)
from strawberry.
Related Issues (20)
- Incongruity with the `Context` type across the library. HOT 2
- strawberry.asdict doesn't recognize strawberry.UNSET
- Expose fragments as a property on Info HOT 2
- Unresolved attribute reference 'from_pydantic' in PyCharm HOT 1
- Incorrect template rendering when overriding graphql IDE template HOT 2
- Ability to change StrawberryConfig's relay_max_results value HOT 1
- Pydantic models as a default values in inputs
- To modify status code of GraphQL query/mutation response right before it returns a result HOT 1
- Malformed request with `operationName` that isn't in `query` gives 500 error: `Can't get GraphQL operation type`
- Strawberry cannot resolve type by inheriting a generic type with union type applied to it. HOT 1
- DataLoader custom cache cannot be used with redis HOT 2
- Input extensions, needed for automatic peristed queries
- Maximum recursion depth exceeded when running codegen
- Support codegen for GQL files with multiple operations
- Expore schema directives in schema introspection API HOT 1
- Pyright 1.1.344 reports that a `strawberry.scalar(...)` variable cannot be used for return type annotation HOT 1
- Support Private Fields with Default Fields
- Subscription is not working with permission_classes HOT 3
- `MaskErrors` does not mask validation errors HOT 4
- Unable to disable graphiql by graphql_ide=None HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strawberry.