-
-
Notifications
You must be signed in to change notification settings - Fork 564
Allow objects with __toString in IDType #210
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
Conversation
Thanks for the PR. This is basically what we discussed in #203 (comment) I would appreciate if you add couple test cases in https://github.com/webonyx/graphql-php/blob/master/tests/Type/ScalarSerializationTest.php Then it will be ready for merging. |
I can do that. Just not sure where to put that class with __toString which is needed for this test. Also do you think this is a good approach? I'm new to GraphQL so I'm unsure if it's expected for every GraphQL object to have an ID type field or if it's ok or even preferred to use a custom type for things like UUID (custom type might help with validation for example). I'm not even sure if it's good to use UUIDs with GraphQL in the first place. |
Drop it in the same folder for now, just name with a As for using objects for ids - it should be OK. One problem that this solution doesn't solve though is parsing. Some ID types could be transformed back to object from string (like Relay's global id where you often concat type name and type instance id). But this is out of the scope of this PR. For now we should at least support |
Ok, I'll add the test. Still do you think I should write an UuidType for GraphQL? I can share it of course if I write it. |
If you use it for entity identification then As a rule of thumb - if you can safely replace your ids with any other unique string without breaking clients - then it qualifies as Also in a future version of GraphQL we can see this feature - graphql/graphql-js#914 which can make custom scalars more convenient. |
Test added. Your answer is a bit unhelpful... I use UUIDs as entity identification obviously AND rely on it being a valid UUID - if the user sends a string that is not a valid UUID it will cause an error. I can safely replace the ids with other strings. Or to be more exact with other unique and valid UUIDs. The clients wont break if I change the IDs but they too will rely on them being UUIDs. So should I use custom type or not? |
Thanks! Released in v0.11.5 |
I wouldn't use separate UUID type in your case. |
Alright, thank you! |
|
||
class ObjectIdStub | ||
{ | ||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it expected to have tabs here?
Cheers 👍 |
@theofidry Damn. No of course not. I'm using tabs in my project so IDE automatically used them here... I'll fix it in another PR. |
I'm using Uuid objects from ramsey/uuid as IDs and this library complains because it's an object.
If you think I should do it differently (like using my own GraphQL type for uuids instead of ID) please enlighten me.