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

Confused about API.swift generated file #2768

Open
cosimtaiuz opened this issue Dec 6, 2020 · 4 comments
Open

Confused about API.swift generated file #2768

cosimtaiuz opened this issue Dec 6, 2020 · 4 comments
Labels
amplify/ios Mostly related to iOS software. DataStore Documentation dealing with the DataStore, can be for any/all platform(s) feature-request Request a new feature p3 missing info

Comments

@cosimtaiuz
Copy link

Hello,

I have setup my iOS project as outlined in the steps and it generated both some files in a folder called AmplifyModels and a file called API.swift which I noticed I could remove and the project worked just the same.

I'm confused about this, which of the two generated things should I keep if I'm using Amplify? From my research it looks like the API.swift file is generated if I'm using AppSync directly, but since I'm not why was it?

Thanks!

@palpatim
Copy link
Member

Hi @cosimtaiuz

That's an unfortunate side effect of us supporting GraphQL via both AppSync and Amplify.

API.swift

As you note, this file supports the AppSync SDK. It is generated by:

  • During the amplify push flow, answering "Yes" to the CLI question: "Do you want to generate code for your newly created GraphQL API"
  • Or, if you imported an existing API: running various amplify codegen flows after adding your API

Doc reference

AmplifyModels.swift

The AmplifyModels.swift file and the associated model and schema files are are used by Amplify API and DataStore. Amplify CLI writes them to the amplify/generated/models directory when you run amplify codegen models.

If you are using Amplify API or DataStore, you can answer "No" to the CLI question "Do you want to generate code for your newly created GraphQL API" and it will not generate the API.swift file. As you note, you can also simply remove it and it will not affect anything in your Amplify app.

Doc reference

Hope this helps.

@palpatim palpatim transferred this issue from aws-amplify/amplify-swift Dec 11, 2020
@palpatim palpatim added feature-request Request a new feature amplify/ios Mostly related to iOS software. labels Dec 11, 2020
@palpatim
Copy link
Member

Transferred this to the doc repo so we can improve our documentation around this and prevent future confusion. Long-term, we should improve the CLI to detect and skip the AppSync flows unless the CLI detects that the project is using AppSync (or unless the customer explicitly opts in).

@cosimtaiuz
Copy link
Author

Thanks for your reply @palpatim , good to know.

@cosimtaiuz cosimtaiuz reopened this Dec 21, 2020
@palpatim palpatim added the DataStore Documentation dealing with the DataStore, can be for any/all platform(s) label Mar 5, 2021
@palpatim
Copy link
Member

palpatim commented Mar 5, 2021

Next steps

  • On https://docs.amplify.aws/start/getting-started/add-api/q/integration/ios#provision-backend, enhance the message

    Reply No when it asks for ? Do you want to generate code for your newly created GraphQL API.

    With an explanation that this is only for AWSAppSync clients, not for Amplify. We should see if it makes sense to add a note that answering "Yes" to this question will generate the API.swift file?

  • Open an issue or PR with the CLI repo to update the message the CLI asks, and indicate that this is only applicable for AWSAppSync clients, not for Amplify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
amplify/ios Mostly related to iOS software. DataStore Documentation dealing with the DataStore, can be for any/all platform(s) feature-request Request a new feature p3 missing info
Projects
None yet
Development

No branches or pull requests

3 participants