-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Q: Error: Unexpected arg kind: ObjectValue #100
Comments
The main reason we didn't support input objects right off the bat is that it's possible for them to contain nested variables, which complicates processing of arguments at runtime. It isn't too difficult to add support for them, but the simple workaround is a variable as you suggested. Example nested variable:
|
Thanks for the explanation @josephsavona! A quick follow up question: I changed this to a variable like this: module.exports = Relay.createContainer(Movie, {
initialVariables: {
orderBy: { field: 'name', order: 'DESC' },
},
fragments: {
movie: () => Relay.QL`
fragment on Movie {
id,
credits(first: 10, orderBy: $orderBy) {
edges {
node {
name
}
}
}
}
`,
},
}); Now I'm getting an error on the server: |
This is a known limitation - we didn't have time to add support for printing enums inside input objects. Again, this isn't difficult but it requires adding quite a bit more metadata about arguments in order to print them correctly. cc @leebyron @dschafer is there anything we can do to make it easier for tools to autogenerate valid inputs? |
@josephsavona I noticed the enum values sent separately in the request body using the I wonder if I could somehow force them to be sent separately and use this to work around the fact that enums can't be printed. If not, I'll just try to avoid enums in input objects for now. |
Relay inlines all variables in queries in order to allow the same fragment to be used with different values. The For an example of why inlining is necessary, consider the // Parent component
foo: () => Relay.QL`
fragment on Story {
author {
${ProfilePicture.getFragment('photo', {size: 64}), # large photo for author
},
comments {
...
${ProfilePicture.getFragment('photo', {size: 32}), # small photo for commenters
}
`
// ProfilePicture:
photo: () => Relay.QL`fragment on User {
profilePicture(size: $size) {...}
} The solution for enums within object values is to construct a new variable for every input object, so that it can be sent as plain JSON instead of an inline value. |
Thanks for the explanation @josephsavona. That makes sense. Just making sure I understood the proposed solution for supporting enums within object values, if we were to implement that the fragments and variables sent to the server would be something like this?
variables (with generated unique names):
|
Heads up that I'll send a PR for this soon. |
I've started adding support here - https://github.com/josephsavona/relay/commits/inputobjects - but this will also require some upstream changes. |
@josephsavona Looks good so far! Noticed |
Correct me if I'm wrong: |
Yup, that's is. This is the same Relay we use internally and the forks account for the (minor) differences in GraphQL versions. |
I tried to pass an input object as an argument to a field, which resulted in following error:
Unexpected arg kind: ObjectValue
.The fragment in question looks like this:
The error is thrown here, in GraphQLPrinter.js. It seems only builtin scalar types and variables are supported by GraphQLPrinter. Does this mean the only way to pass an input object in Relay is to write
credits(orderBy: $orderBy)
and pass it in the variables instead?The text was updated successfully, but these errors were encountered: