Skip to content
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

Fix 'id' getter MSTGQLRef #319

Merged
merged 3 commits into from
Apr 12, 2021

Conversation

weglov
Copy link
Contributor

@weglov weglov commented Apr 2, 2021

This PR contains a small fix for getting the node.id in MSTGQLRef.

Problem:
When I create my mobxStore from a snapshot during testing, the models do not call a setter where their id must be modified and a separator added.

RootStore.create({
   items: {
       '1': {id: '1', name: 'one'},
       '2': {id: '2', name: 'two'}
   },
   myRef: ['1'] //  MSTGQLRef(types.late((): any => ItemModel)),
})

Also, you can look real example in test https://github.com/mobxjs/mst-gql/pull/319/files#diff-8da68bbe119c10527a005b652d591c418c435a78af66333be4e4608e5fc3cc72

I got: Failed to resolve reference to late(() => ItemModel.ItemModel), as you can see without id becouse id in this case just empty space ''

So, this happens because in this case not fires this code: https://github.com/mobxjs/mst-gql/blob/main/src/MSTGQLObject.ts#L41-L43

And my solution will fix that, although I'm not sure if it's the right solution, but it works for me and theoretically can't cause problems.

@weglov weglov changed the title Fix getter id for MSTGQLRef Fix 'id' getter MSTGQLRef Apr 2, 2021
@weglov
Copy link
Contributor Author

weglov commented Apr 2, 2021

@emckay hi, I'd be glad for you to see this PR because it's closely related to your changes.

@emckay
Copy link
Contributor

emckay commented Apr 2, 2021

Thanks @weglov.. Will take a look this afternoon!

@emckay
Copy link
Contributor

emckay commented Apr 2, 2021

Thanks for debugging this and sorry about introducing the breaking change!

Right now, the problem you're running into is that if there's no delimiter in the id, then getMSTGQLRefLabelAndId returns {label: 'something', id: ''}. I think that ideally we'd return { label: null, id: 'something' }. This PR returns { label: 'something', id: 'something' }

Would you mind updating your PR to return label: null if there's no delimiter in the string? Happy to take a stab at it if you don't have time!

@emckay
Copy link
Contributor

emckay commented Apr 5, 2021

Looks good! @jesse-savary do you mind reviewing + merging this?

@jesse-savary jesse-savary merged commit 919890a into mobxjs:main Apr 12, 2021
@jesse-savary
Copy link
Member

Looks good, thank you @weglov

@weglov
Copy link
Contributor Author

weglov commented Apr 19, 2021

@jesse-savary I will be happy if you published new version 🙂 14.0.1

@jesse-savary
Copy link
Member

Oops, still getting the hang of this. Will cut a release shortly!

@jesse-savary
Copy link
Member

Published @weglov :)

@weglov
Copy link
Contributor Author

weglov commented Apr 20, 2021

@jesse-savary Thank you, but you probably forgot to publish npm package, still 14.0.0 https://www.npmjs.com/package/mst-gql

@jesse-savary
Copy link
Member

Odd, I'll take a look shortly

@jesse-savary
Copy link
Member

@weglov resolved, apologies for the delay! I accidentally published 0.14.1 to my private registry instead of NPM :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants