You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Amplify API and Datastore dependencies
implementation("com.amplifyframework:core:2.14.6")
implementation("com.amplifyframework:aws-api:2.14.6")
implementation("com.amplifyframework:core-kotlin:2.14.6")
Environment information
# Put output below this line
------------------------------------------------------------
Gradle 8.2
------------------------------------------------------------
Build time: 2023-06-30 18:02:30 UTC
Revision: 5f4a070a62a31a17438ac998c2b849f4f6892877
Kotlin: 1.8.20
Groovy: 3.0.17
Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM: 17.0.7 (JetBrains s.r.o. 17.0.7+0-17.0.7b1000.6-10550314)
OS: Mac OS X 14.2.1 aarch64
</details>
### Please include any relevant guides or documentation you're referencing
https://docs.amplify.aws/android/build-a-backend/graphqlapi/set-up-graphql-api/
Describe the feature request
Currently Amplify SDK only supports generated code for @model type. e.g., Todo is a @model class, hence Amplify is generating ModelMutation or ModelQuery class (Todo implements Model)
val todo = Todo.builder()
.name("My first todo")
.description("todo description")
.build()
try {
val response = Amplify.API.mutate(ModelMutation.create(todo))
Log.i("MyAmplifyApp", "Added Todo with id: ${response.data.id}")
} catch (error: ApiException) {
Log.e("MyAmplifyApp", "Create failed", error)
}
//generated Todo Class
@ModelConfig(pluralName = "Todos")
public final class Todo implements Model {
......
But I have an existing endpoint, which does NOT contain @model annotation to its types. So, generated class does not contain any ModelQuery or ModelMutation class.
// Generated class does not implement Model
public final class Car23 {
..
To use Amplify.API.query, client code has to create SimpleGraphQl request using custom query and, which works, but getting complicated and lots of boilerplate code. see here
private fun getCar(id: String) : GraphQLRequest<String> {
val document = "query GetCar23(\$id: String!) {\n" +
" getCar23(id: \$id) {\n" +
" id\n" +
" name\n" +
" }\n" +
"}"
return SimpleGraphQLRequest(
document,
mapOf("id" to id),
String::class.java,
GsonVariablesSerializer()
)
}
=============================================
val response = Amplify.API.query(getCar("some_id))
val gson = Gson()
val graphqlResponse = gson.fromJson(response.data, Car::class.java)
However Aws App Sync SDK has the ability to generate all query/mutation/subscription classes, and client App does not require to create a custom query or boilerplate code. It is quite easy to use. Since it is advised to use Amplify SDK instead of Aws App Sync SDK, it would be great if Amplify SDK also has the same ability.
Initialization steps (if applicable)
No response
Code Snippet
// Put your code below this line.// Expecting GetCarQuery is a generated class by the Amplify SDKval response =Amplify.API.query(GetCarQuery("some_id")
or// Expecting CarCreationMutation is a generated class by the Amplify SDKval response =Amplify.API.mutate(CarCreationMutation.create(car))
Before opening, please confirm:
Language and Async Model
Kotlin - Coroutines
Amplify Categories
GraphQL API
Gradle script dependencies
Environment information
Describe the feature request
Currently Amplify SDK only supports generated code for @model type. e.g., Todo is a @model class, hence Amplify is generating ModelMutation or ModelQuery class (Todo implements Model)
But I have an existing endpoint, which does NOT contain @model annotation to its types. So, generated class does not contain any ModelQuery or ModelMutation class.
To use
Amplify.API.query
, client code has to create SimpleGraphQl request using custom query and, which works, but getting complicated and lots of boilerplate code. see hereHowever Aws App Sync SDK has the ability to generate all query/mutation/subscription classes, and client App does not require to create a custom query or boilerplate code. It is quite easy to use. Since it is advised to use Amplify SDK instead of Aws App Sync SDK, it would be great if Amplify SDK also has the same ability.
Initialization steps (if applicable)
No response
Code Snippet
amplifyconfiguration.json
GraphQL Schema
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: