Git Product home page Git Product logo

Comments (3)

sciyoshi avatar sciyoshi commented on May 19, 2024 1

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:

  1. 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.
  2. Use dataclasses' default repr behavior, and add a repr to the actual GraphQL type, i.e. repr(Example.field). Requires either monkeypatching or extending graphql types, or upstreaming this behavior to graphql-core-next.
  3. 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.

patrick91 avatar patrick91 commented on May 19, 2024

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.

patrick91 avatar patrick91 commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.