-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[WIP] Allow objects parameters in mutations #252
Conversation
@prevostc: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/ |
I think the way to do this is to use Basically, what you're doing here is using the AST nodes for the object in the store, but we need to use the actual values. |
All right, I did find how to use that function but I can't find a way to get the right |
@prevostc Since the goal of your PR is to support objects as inputs to mutations, I think what you're looking for is |
@helfer sorry I didn't explained the whole story, I do need a
I did some research and the |
Oh, yes, of course you need an instance. Getting the type from the schema works just fine if you have the schema, but we're trying not to require having the schema on the client, because it means either doing an extra round-trip, or making the build process more complicated. Since in Apollo client mutations with input objects as variables currently don't do any validation, it probably makes most sense to do the same with inline input objects, i.e. just parse the thing without bothering to check the types at all. To achieve that, you can copy the Does that make sense? |
Thanks @helfer for the guidance. After some heavy code reading, I did not copied the Instead I reworked the existing I'm not sure that this new function should be named |
That's great! |
@helfer done \o/ Should I do something else ? |
@prevostc one thing you should do is sign the CLA - it lets us make sure that people are contributing code that they own. |
// utilities/valueFromAST.js |
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.
We don't need this, do we?
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.
Without this declaration, the ts compilation fails. As for the comment line, I tried to use the same convention already present in the file that is to have a section prefixed with the corresponding file name.
I would really prefer to have a few more tests here though - just changing that one doesn't really cover a lot of space of possible arguments. We could just add tests for |
@prevostc Any update on this? I'd like to merge it as soon as there are some more tests and you've signed the CLA. |
@helfer I will be able to add more tests by Monday. I will add more Object to string representation tests, including all scalar types, aliases, 2 or 3 levels of nested object, arrays, arrays of objects and edge cases like nulls and cycling references. |
@prevostc Perfect, I think it shows up as signed now. I don't think you need to test cycles, since the AST gets parsed from a query string, which cannot possibly have any cycles. Everything else sounds good. 2 levels of nesting should be enough. |
return nestedArgArrayObj[name.value]; | ||
}); | ||
} else { | ||
throw new Error(`For inline arguments, only scalar and Object types are supported. |
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.
Probably this should just say enum arguments are not supported, since I think we have covered literally everything else: http://facebook.github.io/graphql/#Value
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 added Enum support in the next commit and reworked the error message to be more generic.
I'd request that we add tests that ensure that arguments are serialized the same way if they are passed via inline AST or variables. |
@stubailo only numbers are not handled the same way, integers are not cast to numbers when inlined. fixing this broke some tests (see below), I don't know what's the right fix here.
|
Hmm I think we should make integers always cast to numbers and update the tests. Strings in graphql literals always have quotes, so it shouldn't be ambiguous I think! |
By the way, thanks for putting so much time into the PR, this is really great stuff. |
@@ -979,10 +979,10 @@ describe('QueryManager', () => { | |||
}); | |||
}); | |||
|
|||
it('runs a mutation and puts the result in the store', () => { | |||
it('runs a mutation with object parameters and puts the result in the store', () => { |
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.
It's not clear what exactly this test is supposed to do. Originally it was to test that the result of a mutation is properly put in the store. We should keep the old test and create an additional one for object values.
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.
This test was a duplicate from the test at line 938, I just reused it instead of dropping it and recreating 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.
Ah, yes, I didn't see that.
@prevostc This is shaping up very nicely, thanks a lot for all your work! My only nitpick is with the tests. Currently, there's just one unit large test that presumably covers all of your changes. If this test fails in the future, it will be very hard to determine what exactly isn't working. Instead of writing one big test, we generally try to test each bit of functionality separately with a smaller test. So you should write a separate test for each branch of the
You can do that by importing the The big test you wrote is more like an integration test, so it's a perfectly good test that you should keep, but it should run after the smaller unit tests for the |
@prevostc Just give me a nudge when you think it's ready to be reviewed again, ok? |
@helfer I added a unit test that cover each case individually. I did the "data provider" manually, maybe there is a best way :s |
Ah, ok, I wasn't sure if you were still working on it or not, so I didn't take a look yet. It will have to be rebased before we can merge, but I can take a look first. |
@prevostc The new tests look great! 👍 This is 99% ready to merge, just some tiny things to fix. I took a look at the coverage report, and it seems there are still two lines that aren't tested at all. You can see them here: https://coveralls.io/builds/6534889/source?filename=src%2Fdata%2FstoreUtils.ts Can you add two tests that cover these lines? One is for a missing variable, the other is for unsupported inline type (just enum, I believe). Also, please rebase your PR so it can be merged without conflict. If you're not sure how to do that, just message me on the apollo slack. |
This PR is amazing. |
@helfer Done :) I also squashed all commits so you can keep a clean commit history too. |
Awesome, amazing work, thank you very much! PS: For next time it's easier if you don't squash the commits, because we can do that with the "squash and merge" option in github. It's easier to review the changes if it's not squashed. |
Oups, sry. Thanks for you careful reviews and your time! |
No worries, thanks a lot for the PR, it's really great! It would be really cool if you want to be an active contributor! I can add you to our team, so you can work on branches directly on this repo. How does that sound? |
I am wondering how the suggested workaround with variables was working before this PR. I have the code below, but I am getting an error.
|
What does the error say? |
|
This issue have been fixed by the merged PR but as a quickfix you could pass the
|
@prevostc has the right workaround. Since |
Imperative read and write docs
Fix broken link in simple-example
This is a work in progress to add support for object parameters in mutations and thus support reindex.io default mutation format.
I did succeed in making all tests pass BUT the fix is obviously wrong so I reach out here to get feedback on which other part of the project should be breaking so I can add some tests there and create a proper fix.
I also reused a duplicated test.