Make arguments accecpt number|boolean|string|object#844
Make arguments accecpt number|boolean|string|object#844iamchenxin wants to merge 14 commits intofacebook:masterfrom
Conversation
src/query/RelayFragmentPointer.js
Outdated
| let argType = typeof identifyingArgValue; | ||
| invariant( | ||
| typeof identifyingArgValue === 'string' || identifyingArgValue == null, | ||
| typeof argType === 'string' || identifyingArgValue == null |
There was a problem hiding this comment.
Since your aim is to support every type of argument, you should simply be able to remove this invariant.
|
@steveluscher Thank you,i will fix them all this evening. |
|
@steveluscher Need one more day to complete this. I think maybe the object-arg would be placed as a value for key 'callValue' ? From RelayQLPrinter.js#L466 and RelayQLAST.js#L361 ,it seems there is no ObjectType support at all level RelayQLArgument. |
|
@steveluscher Need help , When i use t.valueToNode from Its my first time to look into a babel plugin,so there are so much things i do not known. And i search the babel-handbook ,find some function like Go to sleep,see you tomorrow,thanks. Seems i have wrong typing .. |
src/store/RelayRecordUtil.js
Outdated
| } | ||
|
|
||
| } | ||
| }; |
There was a problem hiding this comment.
how is this different than the existing stableStringify function?
There was a problem hiding this comment.
@steveluscher ! Oh! i havent notice this function stableStringify .
Its my fault, i thought you let me rename my function to stableStringify , how stupid am i.
There was a problem hiding this comment.
Need to sleep, will check that function tomorrow. and fix it
|
@steveluscher Almost done. and need some help. |
| } | ||
| } | ||
|
|
||
| // todo array! |
There was a problem hiding this comment.
Does one of objectify or codify already do most of this?
There was a problem hiding this comment.
Yeah, objectify already implements most of printObject. Let's just change the core line:
properties.push(property(key, t.valueToNode(value)));
To check the type of value and recurse if it is a nested object/array. Note that any helper functions can be moved out of the class definition to the bottom of the file.
|
@josephsavona @steveluscher Now the only failed test is this: CheckinSearchInput! vs CheckinSearchInput ( should check this,tomorrow) And i have not set the webstorm right for eslint, so i will modify the code style later by hand,when i finish them. (i need to search how to get webstorm load the eslint plugins ?). |
| case 'ListValue': | ||
| return inputObject.values.map(v=> | ||
| getInputObjectValue(v) | ||
| ); |
There was a problem hiding this comment.
could simplify with return inputObject.values.map(getInputObjectValue)
…and need to write unit test for new functions
Make all identifyingArgValue to `mixed type`. And delete some outside `not null check` for call stableStringify,to avoid get some magic result between files.
3e217b7 to
9e92617
Compare
|
@kassens thank you , rebased |
|
@josephsavona should this need reimport? it rebased after import. |
|
Yup, i'll rebase internally. |
|
@facebook-github-bot import |
|
Thanks for importing. If you are an FB employee go to Phabricator to review. |
|
@iamchenxin Thanks so much for working on this. When I imported and reviewed the code, I realized that all of the call sites of |
Summary:This is an expanded portion of just the plugin changes from [#844](#844). The goal of that PR is to support arbitrary values in identifying arguments. Part of that means supporting input objects, which we didn't fully support in the plugin (we only allowed the value of an input object argument to be a variable, not a literal). Changes: - Support parsing and printing literal InputObject expressions. - Clear error message when variables appear nested in ways that the Relay runtime cannot interpret. - Tests for the above. Closes #894 Reviewed By: yungsters Differential Revision: D3002163 Pulled By: josephsavona fb-gh-sync-id: d7708b36bc087bdd744c4d027cf4b888e8350798 shipit-source-id: d7708b36bc087bdd744c4d027cf4b888e8350798
Summary:Note: this is inspired by and partially based on iamchenxin's work in #767 and #844. Thanks for the head start! Relay currently assumes that identifying argument values are strings (numbers *sort* of work, but not really). This builds on #894 (which added support to the plugin for parsing/printing literal InputObjects) by allowing identifying arguments to be basically anything - boolean, number, string, or array/object of the the same. Key changes include: - Change the `CallValue` type from mixed to an explicit list of the supported types - Change `forEachRootCallArg` to return both the literal JS value of the argument as well as a serialized key - Change all callers of `forEachRootCallArg` (and some places that manually inspected the identifying arg) to correctly choose between the identifying argument value (i.e. when constructing a query with it) or the identifying argument key (for use with `RelayRecordStore.{putDataID,getDataID}`). - Added tests that the writer correctly creates root records with numeric/object identifying argument values. Closes #895 Reviewed By: yungsters Differential Revision: D3003201 Pulled By: josephsavona fb-gh-sync-id: 43ffbbd37e8d2bd8c0abe2cb792ad8959efb7a42 shipit-source-id: 43ffbbd37e8d2bd8c0abe2cb792ad8959efb7a42
|
@josephsavona Its okay. Hope i did not add some hidden bugs in , and will keep a watchful eye on them. |
Summary:This is an expanded portion of just the plugin changes from [facebook#844](facebook#844). The goal of that PR is to support arbitrary values in identifying arguments. Part of that means supporting input objects, which we didn't fully support in the plugin (we only allowed the value of an input object argument to be a variable, not a literal). Changes: - Support parsing and printing literal InputObject expressions. - Clear error message when variables appear nested in ways that the Relay runtime cannot interpret. - Tests for the above. Closes facebook#894 Reviewed By: yungsters Differential Revision: D3002163 Pulled By: josephsavona fb-gh-sync-id: d7708b36bc087bdd744c4d027cf4b888e8350798 shipit-source-id: d7708b36bc087bdd744c4d027cf4b888e8350798
Summary:Note: this is inspired by and partially based on iamchenxin's work in facebook#767 and facebook#844. Thanks for the head start! Relay currently assumes that identifying argument values are strings (numbers *sort* of work, but not really). This builds on facebook#894 (which added support to the plugin for parsing/printing literal InputObjects) by allowing identifying arguments to be basically anything - boolean, number, string, or array/object of the the same. Key changes include: - Change the `CallValue` type from mixed to an explicit list of the supported types - Change `forEachRootCallArg` to return both the literal JS value of the argument as well as a serialized key - Change all callers of `forEachRootCallArg` (and some places that manually inspected the identifying arg) to correctly choose between the identifying argument value (i.e. when constructing a query with it) or the identifying argument key (for use with `RelayRecordStore.{putDataID,getDataID}`). - Added tests that the writer correctly creates root records with numeric/object identifying argument values. Closes facebook#895 Reviewed By: yungsters Differential Revision: D3003201 Pulled By: josephsavona fb-gh-sync-id: 43ffbbd37e8d2bd8c0abe2cb792ad8959efb7a42 shipit-source-id: 43ffbbd37e8d2bd8c0abe2cb792ad8959efb7a42
Please review me.
Template commit for review.
This fix just covert the input
identifyingArgValue(string|number|object) ingetDataIDandputDataIDto a string.Because GraphQL is already a type system ,so the number is covert to plain string,do not use maker to distinguish from string.
The object is covert to something like JSON,but with sorted key-value.
At this time , i m a bit confused by Object args, maybe should fix more file to accept this.
at now unit test stop at
RelayQLAST.js:435.The failed unit test is object arg
worked in raw GraphQL server,but failed in relay. So this should be an additional type check error in RelayQLAST?
Continue tomorrow.