-
Notifications
You must be signed in to change notification settings - Fork 106
Add support for void return type #574
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
…lone usages in return types
| @@ -0,0 +1,52 @@ | |||
| <?php | |||
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.
So, I'm a little confused on the purpose of the src/Types.php file. It seems like you're creating this as a means of separating out the GraphQLite "custom-ish" types. But, I don't really see how these differ much from the other types in the Types dir. They're all internally managed types and pulling out a few seems a bit confusing.
Is the internal caching here providing much value? The instantiation of these objects seems trivial.
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.
The idea is similar to webonyx's Type class with string, id, getNamedType, union etc method, i.e. if you need a type you know right away where to get it from. The value of Types in this case is the same kind of "entry point" for those who need those types in 3rd party type mappers. I'm not worried about caching so much.
For example, in our project we use carbon/carbon instead of php's DateTime, but we still use graphqlite's built in DateTime type to represent Carbon dates it in the Schema and serialize/deserialize them. When more types are added into graphqlite, it will always be easy to navigate and find them.
If you're against providing that kind of public API I'll remove it.
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.
I see. For DateTime, we use a custom type mapper for our internal Date object that maps to a custom Date scalar. We do allow GraphQLite to handle \DateTime and \DateTimeImmutable. We have a few other custom types as well that we manage through our type mapper.
Carbon extends \DateTimeImmutable IIRC. I think GraphQLite should handle the serialization of this already. Of course, you could setup a type mapper to handle the deserialization side as well.
I'm trying to think where this API would even be helpful to a normal developer. And internally, I don't see much benefit over using the type classes directly. You can't type with this interface, requiring the class to be typed directly. I think I'd rather we stick with the type classes directly, for the sake of simplicity and consistency.
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.
I've removed Types. Following the style of BaseTypeMapper, I still used a static property to hold an instance of VoidType, just to avoid the unnecessary instantiations.
Closes #573
On the implementation: I've implemented
VoidTypeMapperseparately from the rest to make sure it only ever matches standalone output types, i.e. that it can't be used in a union or as an input or anything else that doesn't make sense.NullableTypeMapperis no longer the "top root type mapper" - that's because void type must not be wrapped inNonNullas that causes an error when actually running a mutation withvoidreturn.