Skip to content

Add note for arguments restriction in query#767

Closed
iamchenxin wants to merge 1 commit intofacebook:masterfrom
iamchenxin:docs-router
Closed

Add note for arguments restriction in query#767
iamchenxin wants to merge 1 commit intofacebook:masterfrom
iamchenxin:docs-router

Conversation

@iamchenxin
Copy link
Contributor

No description provided.

@josephsavona
Copy link
Member

@steveluscher thoughts on this? The restriction on string arguments is largely arbitrary, how hard would it be to just allow any type?

@steveluscher
Copy link
Contributor

Thanks for these contributions, @iamchenxin!

Instead of warning and documenting (#764) this behavior, how would you feel about fixing it? Here's what needs to happen:

Right now, we use the identifyingArgValue as a key in the rootCallMap and cachedRootCallMap of the RelayRecordStore. This is a map from identifyingArgValue to DataID. Because keys can only be strings, we enforce that every root call's identifyingArgValue is a string.

What you could do to fix this would be to modify getDataID and putDataID (link)to accept identifyingArgValues other than strings, then to stringify them if they are not already a string:

  • If identifyingArgValue is already a string, use it as the key like normal
  • If identifyingArgValue is an object, stringify it using stableStringify and use the result as the key

Are you up for that?

@iamchenxin
Copy link
Contributor Author

@steveluscher I am not familiar with Relay yet,and I am learning both Relay and English these days ,So when i make sure i can figure out the meaning of most Relay Store's functions, i should and would do this. Maybe one or two weeks later.
BTW: I thought the string restriction is deliberately designed before . When i first learn to use relay, i tried to pass Object and int as args to the top-level .But then the string restriction lead me to another design semantic .. keep the top-level fields of query as simple interfaces.

I am learning more about Relay, then i may not be confused with the relationship between each parts.

@steveluscher
Copy link
Contributor

Someone just hit this restriction internally, where their identifying argument was an integer. Relay, as you've noticed above, turned it into a string. If you have time to open Relay up to objects, integer, and string identifying arguments, that would be a tremendous help, @iamchenxin!

@iamchenxin
Copy link
Contributor Author

@steveluscher Just back from Chinese new year today, i will try to fix it tomorrow .

@vdurmont
Copy link

Hi @iamchenxin ! I had the same problem when I tried to use an integer identifying argument. If you have the opportunity to look into this issue, it would help a lot! Let us know if you need help!

@iamchenxin
Copy link
Contributor Author

@vdurmont in the process of writing unit test , will pull the code before i go to sleep.
writing additional type for test in testschema.graphql now.

@iamchenxin
Copy link
Contributor Author

@vdurmont hi,i go to sleep. and update the uncompleted code to a new pull request. (you review them first, check if i got the right idea).
#844.
Im not familiar with flow and jest. so i use ?any temporarily (should be something like number|string|object).
number support should already worked.
Object support maybe need modify more files? but maybe im tired so i misunderstand some files,or i write wrong GraphQL type for test. will continue tomorrow.

@josephsavona
Copy link
Member

@iamchenxin Thanks for starting the discussion about this! I've created two new PRs that build on these ideas in #894 and #895, so let's continue discussion there.

ghost pushed a commit that referenced this pull request Mar 3, 2016
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
venepe pushed a commit to venepe/relay that referenced this pull request Mar 7, 2016
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants