-
Notifications
You must be signed in to change notification settings - Fork 128
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
Why isn't swift returning my 1:m model data? #376
Comments
Facing the same issue, I have increased the maximum depth to 8 and I still see nil on "items" from the iOS client. |
Hi dgaeta, after A LOT of research, it isn't exactly clear, but I have worked out how it needs to be done. The cli will create a graphql folder in your main xcode project, in here you will find the queries.graphql, mutations.graphql etc, and from here the cli generates the API.swift file that you can use to query the data directly from swift. What you need to do is create your OWN graphql file in this folder, with your queries that you use in AWS AppSync console. So as an example, my original post above referenced the above code that would get all the post items associated with a user.
this would need to be added to your myqueriesfile.graphql file that you have added to the graphql folder in your main xcode project. But this query isn't ready to be used yet, you need to make a modification so that you can use the id, so the above would look like:
Once you have your query in your file, you need to regenerate the code, so I think you can either do amplify codegen or amplify push, and the cli will generate this method in your API.swift. Once that is done, you can then access the items :) Let me know if that isn't clear. |
hi @mickeysox, thanks for sharing your research for others to learn from. I could not reproduce the issue with missing posts when retrieving the user.
This looks correct to me as the selection set contains items corresponding to the posts in the User.
I am currently using amplify CLI 4.12.0 Which version of Amplify CLI are you using? |
Hi @lawmicha Thank you very much for your feedback, that makes absolute sense what you are suggesting, it seemed odd this wasn't something that worked out of the box. I have created a brand new project and followed your exact suggestions, but it hasn't worked. My GetUser is as follows:
Which doesn't display the items under posts. Just to confirm, this was based on entering the Maximum depth of 2, as you have suggested. However if I run amplify codegen configure and change it to 3, my output is...
from the generated queries.graphql file
The changes I have made...
I find it strange that 2 isn't enough? In answer to your questions: Which version of Amplify CLI are you using? 4.17.2 Any thoughts? Thank you so much for your reply, I really appreciate it. |
thanks for details, I would expect a max depth of 2 to be generating the correct selection set. since it was working in 4.12.0 (version I used) then there may have been a change that was introduced. i've opened an issue over in the CLI repo https://github.com/aws-amplify/amplify-cli/issues/3971 |
Thanks @lawmicha I appreciate that. The good news is that the code is being generated as I originally expected and no further queries are necessary to retrieve the lower levels. Albeit unintuitive to have 3 levels instead of 2. Thank you again for your support, it did feel like a hack to have to manually generate the query!. Hopefully the guys can clarify on the bug report. |
Please refer to this comment aws-amplify/amplify-codegen#23 (comment) for a workaround. |
I have a 1:m relationship, but when I query the User to get all the associated posts, I am not getting back any posts.
output:
Whereas if I run this ListPosts I can see all the posts. As you can see from the grapql queries, the data is associated, so I am unsure what I am doing wrong?
The text was updated successfully, but these errors were encountered: