-
Notifications
You must be signed in to change notification settings - Fork 2k
Wrapper method on type classes #1054
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
It's not obvious to me what is "nicer" about it. Can you explain? |
@wincent To me, it's nicer:
|
@mohawk2 Great feature 👍 It allows comparing types directly ( So you can't make this assumption in your code especially if you using any 3rd-party library (e.g. graphql-relay-js) to construct your schema. I wish it was implemented before public release of
Alternative solution could be: |
@IvanGoncharov Very interesting possibilities! I am thinking less adventurously: that with the memoising wrap methods, the trivial case of By the way, only having |
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'd much prefer that graphql-js avoid adding additional methods to types, especially for type construction. I would be happy to review a PR which provides convenience functions for constructing wrapping types. WeakMaps could be used for memoization if that's still preferred.
I'm going to close this PR for repo maintenance, but if you rebase with new changes please feel free to reopen it! |
@leebyron I will certainly do so (and thanks for the warning about why the close :-) ). In particular, I am happy to switch it to a function if you require that. I would note and argue that in this specific case, there is a genuine syntactic benefit to being a method, because that makes it postfix. That makes it a good match for at least the NonNull specification in the SDL. Before I go ahead, it would really really help if you could look at the PR I linked above (mohawk2#1) which has a Flow error for the NonNull version of this, despite looking identical to me. If it's not obvious to you almost immediately, then don't worry (but please say) and I will dig into debugging Flow/my code. |
I've made some improvements in the master branch both to defining non-null and list (no longer need the |
The flow error you're encountering is due to using the |
Thanks for taking a look! |
@leebyron I have updated the PR! However I don't seem to be able to re-open it, could you or someone? I added the memoising with the WeakMap per your suggestion, and after some Flow nightmares it all seems to work. It even seems (using my benchmark) to be a few percent faster! @IvanGoncharov I switched to using your idea of wrapType(GraphQLInt, '!]!]!'); That seems to me very concise and expressive. Thanks! |
It's not because of access rights since I also see this message: It looks like GitHub limitation: isaacs/github#361 |
Hi @IvanGoncharov, what a strange limitation! Thanks for the information. Anyway, I've re-force-pushed this back to the old commit. Could you reopen it so I can force-push the new code? In meantime you can look at it on https://github.com/graphql/graphql-js/compare/master...mohawk2:wrapmethods-new?expand=1 if you want to. |
Rather than constantly do:
it would be nicer to do:
It would be even nicer if the other type could memoise the "list" version, which would be safe because all these objects are immutable. This PR implements that.
Not included in the PR yet, since it is not working: I am trying to do the same for a
wrapNonNull
method but it is giving a strange type failure. It is particularly strange to me because the same syntax and type declarations work fine on thewrapList
method. This is an excerpt of the error:It seems to be losing the "type application" on
GraphQLNonNull
. It did this even when I adjusted the return type ofwrapNonNull
fromGraphQLNonNull<*>
toGraphQLNonNull<GraphQLScalarType>
. Any insight into why would be greatly appreciated!