The is no AWSAppSync module error in generated API.swift iOS

0

We are using Amplify-swift framework for auth, also added API plugin. So we could add the Api to our amplify project in backend using codegen. when done with codegen an API.swift file is generated, which includes #import AWSAppSync.

It seems that there is no AWSAppSync framework in Amplify . I see that some suggested to uses aws-mobile-appsync-sdk-ios framework. But if I try to include this package using SPM we get resolution failure error.

We want to use both Auth from amplify framework as it is already setup in our project and API Appsync. How to solve this issue?

1 Answer
0

The API.swift file is generated,


→ During $. amplify push operation, when we answer: “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.

AmplifyModels.swift


The AmplifyModels.swift file and the associated model and schema files are are used by Amplify API and DataStore.

This file is generated, when you run amplify codegen models and the Amplify CLI writes them to the amplify/generated/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.

Please refer to the below Github issues:


[+] https://github.com/aws-amplify/docs/issues/2768#issuecomment-743315401
[+] https://github.com/aws-amplify/amplify-codegen/issues/505#issuecomment-1297309379

Now, if you would like to use API Appsync, you need to add the dependency as mentioned here:


[+] https://github.com/awslabs/aws-mobile-appsync-sdk-ios#installing-the-sdk
[+] https://github.com/aws-amplify/amplify-codegen/issues/505#issuecomment-1319000253

Thanks!

AWS
SUPPORT ENGINEER
answered a year ago
  • Thank you for the response. Just to clarify from your comment. It means we can't use the auto-generated API.swift/AmplifyModels.swift alongside with amplify.

    My scenario is that we have already created an API with all the schemas, queries etc in backend. So I was looking for option similar to the one available with auth i.e."amplify import auth". But it seems the only way to configure amplify with the existing API is through "amplify codegen". And this will auto-generate the model swift file based on the existing schema , queries etc.

    But this auto-generated file cannot be used alongside amplify as it uses AWSAppSync framework which is available only as separate package and cannot be included along with amplify framework.

    So as you mentioned we can remove this auto-generated file from the project and it will build. This is fine. But in that case what is the way to make a queries/update backend to API using Amplify?

    There are some examples shown in the amplify document for API, but it seems not sufficient and clear, it describes solely with respect to new schemas that are created via "amplify add api" and is operated on this data.

    So is there any iOS sample that uses pure amplify to make queries and retrieve data and also update the data to backend to the schemas that is created the way that I had explained above (i.e. by "amplify codegen"). If you can provide this it will be of great help.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions