Giter VIP home page Giter VIP logo

Comments (2)

bellini666 avatar bellini666 commented on July 19, 2024

Hi @ashishnitinpatil ,

You can change the attribute that is used to retrieve the id using id_attr or even by defining your own resolve_id

Now, if I understood correctly, you want to also change how it is serialized, so instead of being serialized as a base64 of <Type>:<Id> you would only want <Id>? That might be problematic for the following reason:

The globalid should be something unique and that you can usually retrieve the object back by having just it. For example, if I have an object with id 2022-06-07-001 as you described, for which type is it? Is it an OrderType, an UserType or even a ProductType? That is the reason that usually the type is serialized together.

Having said that, you can probably create a custom directive to use on GlobalID scalars, which would retrieve those and get you the id directly. For example, you could use it like this on the client:

order {
  id
  extractedId: id @extractGlobalId
}

In the example bellow, the id still is the globalid as a base64, but the extractedId would be the id that your directive returned, which can be implemented to return the id directly.

What do you think of those approaches? Of am I missing something on what do you want to do?

from strawberry-django-plus.

ashishnitinpatil avatar ashishnitinpatil commented on July 19, 2024

Thanks for the helpful response @bellini666 !

I tried defining the id_attr on my type earlier, but it doesn't work as intended, maybe overriding the resolve_id might help. I'll try that.

Your understanding is mostly correct, and I completely get why one should ideally use the combination of <Type>:<Id> but the reason I would prefer just <Id_attr> (in my case number) is that the frontend URLs which use the id would look much better and be human readable, not to mention the concern of revealing the database autoincrementing ID. Which is why, I don't mind throwing errors when a different type's ID is passed to the APIs that use the <Id_attr> for resolving objects instead of usual <Type>:<Id>.

Hope I'm little more clear.

from strawberry-django-plus.

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.