Closed olliestringfield-accedo closed 6 months ago
@olliestringfield-accedo This is expected. The Amplify Android client library is built to use Amplify models and it does not use the .graphql
files generated. To use non amplify models, the Android AppSync SDK is still available (https://github.com/awslabs/aws-mobile-appsync-sdk-android)
@tylerjroach Thanks for the recommendation. This is odd because the iOS Amplify SDK allows querying for non-Amplify models and the codegen generates queries to use with the SDK without the @model directive. Is this a known feature discrepancy between Android and iOS that will not be aligned?
@olliestringfield-accedo Can you show me a code example for Swift of what you are doing? I want to make sure I'm not misunderstanding anything.
One difference between Swift and Android is that the AWS AppSync SDK for iOS has entered maintenance mode, and the Amplify API category was updated to support a few of the AppSync SDK use cases.
So given the attached schema.graphql
file.
When I run amplify add codegen
, the generated queries are output to the API.swift
file.
We can see the generated GetProductQuery class
public final class GetProductQuery: GraphQLQuery {
public static let operationString =
"query GetProduct($id: ID!) {\n getProduct(id: $id) {\n __typename\n createdAt\n description\n id\n image\n name\n owner\n price\n updatedAt\n userId\n userName\n }\n}"
public var id: GraphQLID
public init(id: GraphQLID) {
self.id = id
}
public var variables: GraphQLMap? {
return ["id": id]
}
...
}
Then we can use this to create a GraphQLRequest<R: Decodable>
object to pass through to the Amplify API category as shown below
func getProduct(id: String) async throws -> GetProductQuery.Data {
do {
let query = GetProductQuery(id: id)
let operation = GetProductQuery.operationString
let responseType = GetProductQuery.Data.self
let request = GraphQLRequest(document: operation, variables: query.variables, responseType: responseType)
let result = try await Amplify.API.query(request: request)
switch result {
case .success(let data):
return data
case .failure(let error):
debugPrint(error.errorDescription)
throw error
}
} catch let error {
debugPrint("Failed to get product id=\(id)")
throw error
}
}
I've added the full generated API.swift for reference API.swift.zip
Hi @olliestringfield-accedo, the use case you are using on the Swift side is the one found in the upgrade guide to use the AppSync SDK API.swift file that was previously used with AppSync iOS SDK. When the SDK was placed into maintenance mode, support was added on Amplify Swift side to allow this file to be used.
Since the Android AppSync SDK is still supported, this migration path has not been enabled. The expectation is still to use the AppSync Android SDK.
Thanks for the clarification @tylerjroach. I'll use the Android AppSync SDK for our use case
This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.
Before opening, please confirm:
Language and Async Model
Kotlin - Coroutines
Amplify Categories
Authentication, GraphQL API
Gradle script dependencies
Environment information
Please include any relevant guides or documentation you're referencing
https://docs.amplify.aws/gen1/android/build-a-backend/graphqlapi/client-code-generation/
Describe the bug
We are implementing the Android Amplify SDK into a Kotlin Android app with no Amplify instance. Instead we are using a Cognito User Pool and AppSync. When putting the schema.graphql from AppSync into the root folder and running the codegen command:
Only
.graphql
files are generated i.eapp/src/main/graphql/com/amazonaws/amplify/generated/graphql/queries.graphql
There is no generated Java or Kotlin code to use with Amplify SDK and use our queries defined in the schema file. Note the schema is not using the @model directive since we are not using Dynamo DBReproduction steps (if applicable)
No response
Code Snippet
Log output
amplifyconfiguration.json
No response
GraphQL Schema
Additional information and screenshots
Output
queries.graphql