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

feat(api): Add AuthMode to ModelSubscription #2829

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[*.{kt,kts}]
#this is to match java checkstyle
max_line_length=120
max_line_length=120
ktlint_code_style=android_studio
1 change: 0 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions aws-api/api/aws-api.api
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ public final class com/amplifyframework/api/aws/AppSyncGraphQLRequestFactory {
public static final fun buildQuery (Ljava/lang/Class;Ljava/lang/String;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun buildQuery (Ljava/lang/Class;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun buildSubscription (Ljava/lang/Class;Lcom/amplifyframework/api/graphql/SubscriptionType;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun buildSubscription (Ljava/lang/Class;Lcom/amplifyframework/api/graphql/SubscriptionType;Lcom/amplifyframework/api/aws/AuthorizationType;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun buildSubscription (Ljava/lang/Class;Lcom/amplifyframework/api/graphql/SubscriptionType;Lcom/amplifyframework/api/aws/AuthorizationType;Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun buildSubscription (Ljava/lang/Class;Lcom/amplifyframework/api/graphql/SubscriptionType;Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static synthetic fun buildSubscription$default (Ljava/lang/Class;Lcom/amplifyframework/api/graphql/SubscriptionType;Lcom/amplifyframework/api/aws/AuthorizationType;ILjava/lang/Object;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
}

public final class com/amplifyframework/api/aws/BuildConfig {
Expand Down Expand Up @@ -263,12 +266,24 @@ public final class com/amplifyframework/api/graphql/model/ModelQuery {
public final class com/amplifyframework/api/graphql/model/ModelSubscription {
public static final field INSTANCE Lcom/amplifyframework/api/graphql/model/ModelSubscription;
public static final fun of (Ljava/lang/Class;Lcom/amplifyframework/api/graphql/SubscriptionType;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun of (Ljava/lang/Class;Lcom/amplifyframework/api/graphql/SubscriptionType;Lcom/amplifyframework/api/aws/AuthorizationType;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun of (Ljava/lang/Class;Lcom/amplifyframework/api/graphql/SubscriptionType;Lcom/amplifyframework/api/aws/AuthorizationType;Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun of (Ljava/lang/Class;Lcom/amplifyframework/api/graphql/SubscriptionType;Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static synthetic fun of$default (Ljava/lang/Class;Lcom/amplifyframework/api/graphql/SubscriptionType;Lcom/amplifyframework/api/aws/AuthorizationType;ILjava/lang/Object;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun onCreate (Ljava/lang/Class;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun onCreate (Ljava/lang/Class;Lcom/amplifyframework/api/aws/AuthorizationType;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun onCreate (Ljava/lang/Class;Lcom/amplifyframework/api/aws/AuthorizationType;Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun onCreate (Ljava/lang/Class;Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static synthetic fun onCreate$default (Ljava/lang/Class;Lcom/amplifyframework/api/aws/AuthorizationType;ILjava/lang/Object;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun onDelete (Ljava/lang/Class;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun onDelete (Ljava/lang/Class;Lcom/amplifyframework/api/aws/AuthorizationType;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun onDelete (Ljava/lang/Class;Lcom/amplifyframework/api/aws/AuthorizationType;Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun onDelete (Ljava/lang/Class;Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static synthetic fun onDelete$default (Ljava/lang/Class;Lcom/amplifyframework/api/aws/AuthorizationType;ILjava/lang/Object;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun onUpdate (Ljava/lang/Class;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun onUpdate (Ljava/lang/Class;Lcom/amplifyframework/api/aws/AuthorizationType;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun onUpdate (Ljava/lang/Class;Lcom/amplifyframework/api/aws/AuthorizationType;Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static final fun onUpdate (Ljava/lang/Class;Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
public static synthetic fun onUpdate$default (Ljava/lang/Class;Lcom/amplifyframework/api/aws/AuthorizationType;ILjava/lang/Object;)Lcom/amplifyframework/api/graphql/GraphQLRequest;
}

Original file line number Diff line number Diff line change
Expand Up @@ -482,18 +482,19 @@ object AppSyncGraphQLRequestFactory {
* Creates a [GraphQLRequest] that represents a subscription of a given type.
* @param modelClass the model type.
* @param subscriptionType the subscription type.
* @param authMode The [AuthorizationType] to use for making the request
* @param <R> the response type.
* @param <T> the concrete model type.
* @return a valid [GraphQLRequest] instance.
* @throws IllegalStateException when the model schema does not contain the expected information.
</T></R> */
*/
@JvmStatic
@JvmOverloads
fun <R, T : Model> buildSubscription(
modelClass: Class<T>,
subscriptionType: SubscriptionType
): GraphQLRequest<R> {
return buildSubscriptionInternal(modelClass, subscriptionType, null)
}
subscriptionType: SubscriptionType,
authMode: AuthorizationType? = null
) = buildSubscriptionInternal<R, T, ModelPath<T>>(modelClass, subscriptionType, authMode, null)

/**
* Creates a [GraphQLRequest] that represents a subscription of a given type.
Expand All @@ -505,19 +506,38 @@ object AppSyncGraphQLRequestFactory {
* @param <P> the concrete model path for the M model type
* @return a valid [GraphQLRequest] instance.
* @throws IllegalStateException when the model schema does not contain the expected information.
</T></R> */
*/
@JvmStatic
fun <R, T : Model, P : ModelPath<T>> buildSubscription(
modelClass: Class<T>,
subscriptionType: SubscriptionType,
includes: ((P) -> List<PropertyContainerPath>)
): GraphQLRequest<R> {
return buildSubscriptionInternal(modelClass, subscriptionType, includes)
}
) = buildSubscriptionInternal<R, T, P>(modelClass, subscriptionType, null, includes)

/**
* Creates a [GraphQLRequest] that represents a subscription of a given type.
* @param modelClass the model type.
* @param subscriptionType the subscription type.
* @param authMode The [AuthorizationType] to use for making the request
* @param includes lambda returning list of relationships that should be included in the selection set
* @param <R> the response type.
* @param <T> the concrete model type.
* @param <P> the concrete model path for the M model type
* @return a valid [GraphQLRequest] instance.
* @throws IllegalStateException when the model schema does not contain the expected information.
*/
@JvmStatic
fun <R, T : Model, P : ModelPath<T>> buildSubscription(
modelClass: Class<T>,
subscriptionType: SubscriptionType,
authMode: AuthorizationType,
includes: ((P) -> List<PropertyContainerPath>)
) = buildSubscriptionInternal<R, T, P>(modelClass, subscriptionType, authMode, includes)

private fun <R, T : Model, P : ModelPath<T>> buildSubscriptionInternal(
modelClass: Class<T>,
subscriptionType: SubscriptionType,
authMode: AuthorizationType?,
includes: ((P) -> List<PropertyContainerPath>)?
): GraphQLRequest<R> {
return try {
Expand All @@ -527,8 +547,12 @@ object AppSyncGraphQLRequestFactory {
.requestOptions(ApiGraphQLRequestOptions())
.responseType(modelClass)

val customSelectionSet = includes?.let { createApiSelectionSet(modelClass, subscriptionType, it) }
customSelectionSet?.let { builder.selectionSet(it) }
authMode?.let { builder.authorizationType(it) }

includes?.let {
val customSelectionSet = createApiSelectionSet(modelClass, subscriptionType, it)
builder.selectionSet(customSelectionSet)
}

builder.build()
} catch (exception: AmplifyException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.amplifyframework.api.graphql.model

import com.amplifyframework.api.aws.AppSyncGraphQLRequestFactory.buildSubscription
import com.amplifyframework.api.aws.AuthorizationType
import com.amplifyframework.api.graphql.GraphQLRequest
import com.amplifyframework.api.graphql.SubscriptionType
import com.amplifyframework.core.model.Model
Expand All @@ -30,16 +31,17 @@ object ModelSubscription {
* Builds a subscriptions request of a given `type` for a `modelType`.
* @param modelType the model class.
* @param type the subscription type.
* @param authMode The [AuthorizationType] to use for making the request
* @param <M> the concrete type of the model.
* @return a valid [GraphQLRequest] instance.
</M> */
*/
@JvmStatic
@JvmOverloads
fun <M : Model> of(
modelType: Class<M>,
type: SubscriptionType,
): GraphQLRequest<M> {
return buildSubscription(modelType, type)
}
authMode: AuthorizationType? = null
): GraphQLRequest<M> = buildSubscription(modelType, type, authMode)

/**
* Builds a subscriptions request of a given `type` for a `modelType`.
Expand All @@ -49,100 +51,170 @@ object ModelSubscription {
* @param <M> the concrete type of the model.
* @param <P> the concrete model path for the M model type
* @return a valid [GraphQLRequest] instance.
</M> */
*/
@JvmStatic
fun <M : Model, P : ModelPath<M>> of(
modelType: Class<M>,
type: SubscriptionType,
includes: ((P) -> List<PropertyContainerPath>)
): GraphQLRequest<M> {
return buildSubscription(modelType, type, includes)
}
): GraphQLRequest<M> = buildSubscription(modelType, type, includes)

/**
* Builds a subscriptions request of a given `type` for a `modelType`.
* @param modelType the model class.
* @param type the subscription type.
* @param authMode The [AuthorizationType] to use for making the request
* @param includes lambda returning list of relationships that should be included in the selection set
* @param <M> the concrete type of the model.
* @param <P> the concrete model path for the M model type
* @return a valid [GraphQLRequest] instance.
*/
@JvmStatic
fun <M : Model, P : ModelPath<M>> of(
modelType: Class<M>,
type: SubscriptionType,
authMode: AuthorizationType,
includes: ((P) -> List<PropertyContainerPath>)
): GraphQLRequest<M> = buildSubscription(modelType, type, authMode, includes)

/**
* Creates a subscription request of type [SubscriptionType.ON_CREATE].
* @param modelType the model class.
* @param authMode The [AuthorizationType] to use for making the request
* @param <M> the concrete type of the model.
* @return a valid [GraphQLRequest] instance.
* @see .of
</M> */
*/
@JvmStatic
fun <M : Model> onCreate(modelType: Class<M>): GraphQLRequest<M> {
return of(modelType, SubscriptionType.ON_CREATE)
}
@JvmOverloads
fun <M : Model> onCreate(
modelType: Class<M>,
authMode: AuthorizationType? = null
): GraphQLRequest<M> = of(modelType, SubscriptionType.ON_CREATE, authMode)

/**
* Creates a subscription request of type [SubscriptionType.ON_CREATE].
* @param modelType the model class.
* @param includes lambda returning list of relationships that should be included in the selection set
* @param <M> the concrete type of the model.
* @param <P> the concrete model path for the M model type
* @return a valid [GraphQLRequest] instance.
* @see .of
*/
@JvmStatic
fun <M : Model, P : ModelPath<M>> onCreate(
modelType: Class<M>,
includes: ((P) -> List<PropertyContainerPath>)
): GraphQLRequest<M> = of(modelType, SubscriptionType.ON_CREATE, includes)

/**
* Creates a subscription request of type [SubscriptionType.ON_CREATE].
* @param modelType the model class.
* @param authMode The [AuthorizationType] to use for making the request
* @param includes lambda returning list of relationships that should be included in the selection set
* @param <M> the concrete type of the model.
* @param <P> the concrete model path for the M model type
* @return a valid [GraphQLRequest] instance.
* @see .of
</M> */
*/
@JvmStatic
fun <M : Model, P : ModelPath<M>> onCreate(
modelType: Class<M>,
authMode: AuthorizationType,
includes: ((P) -> List<PropertyContainerPath>)
): GraphQLRequest<M> {
return of(modelType, SubscriptionType.ON_CREATE, includes)
}
): GraphQLRequest<M> = of(modelType, SubscriptionType.ON_CREATE, authMode, includes)

/**
* Creates a subscription request of type [SubscriptionType.ON_DELETE].
* @param modelType the model class.
* @param authMode The [AuthorizationType] to use for making the request
* @param <M> the concrete type of the model.
* @return a valid [GraphQLRequest] instance.
* @see .of
</M> */
*/
@JvmStatic
fun <M : Model> onDelete(modelType: Class<M>): GraphQLRequest<M> {
return of(modelType, SubscriptionType.ON_DELETE)
}
@JvmOverloads
fun <M : Model> onDelete(
modelType: Class<M>,
authMode: AuthorizationType? = null
): GraphQLRequest<M> = of(modelType, SubscriptionType.ON_DELETE, authMode)

/**
* Creates a subscription request of type [SubscriptionType.ON_DELETE].
* @param modelType the model class.
* @param includes lambda returning list of relationships that should be included in the selection set
* @param <M> the concrete type of the model.
* @param <P> the concrete model path for the M model type
* @return a valid [GraphQLRequest] instance.
* @see .of
*/
@JvmStatic
fun <M : Model, P : ModelPath<M>> onDelete(
modelType: Class<M>,
includes: ((P) -> List<PropertyContainerPath>)
): GraphQLRequest<M> = of(modelType, SubscriptionType.ON_DELETE, includes)

/**
* Creates a subscription request of type [SubscriptionType.ON_DELETE].
* @param modelType the model class.
* @param authMode The [AuthorizationType] to use for making the request
* @param includes lambda returning list of relationships that should be included in the selection set
* @param <M> the concrete type of the model.
* @param <P> the concrete model path for the M model type
* @return a valid [GraphQLRequest] instance.
* @see .of
</M> */
*/
@JvmStatic
fun <M : Model, P : ModelPath<M>> onDelete(
modelType: Class<M>,
authMode: AuthorizationType,
includes: ((P) -> List<PropertyContainerPath>)
): GraphQLRequest<M> {
return of(modelType, SubscriptionType.ON_DELETE, includes)
}
): GraphQLRequest<M> = of(modelType, SubscriptionType.ON_DELETE, authMode, includes)

/**
* Creates a subscription request of type [SubscriptionType.ON_UPDATE].
* @param modelType the model class.
* @param authMode The [AuthorizationType] to use for making the request
* @param <M> the concrete type of the model.
* @return a valid [GraphQLRequest] instance.
* @see .of
</M> */
*/
@JvmStatic
fun <M : Model> onUpdate(modelType: Class<M>): GraphQLRequest<M> {
return of(modelType, SubscriptionType.ON_UPDATE)
}
@JvmOverloads
fun <M : Model> onUpdate(
modelType: Class<M>,
authMode: AuthorizationType? = null
): GraphQLRequest<M> = of(modelType, SubscriptionType.ON_UPDATE, authMode)

/**
* Creates a subscription request of type [SubscriptionType.ON_UPDATE].
* @param modelType the model class.
* @param includes lambda returning list of relationships that should be included in the selection set
* @param <M> the concrete type of the model.
* @param <P> the concrete model path for the M model type
* @return a valid [GraphQLRequest] instance.
* @see .of
*/
@JvmStatic
fun <M : Model, P : ModelPath<M>> onUpdate(
modelType: Class<M>,
includes: ((P) -> List<PropertyContainerPath>)
): GraphQLRequest<M> = of(modelType, SubscriptionType.ON_UPDATE, includes)

/**
* Creates a subscription request of type [SubscriptionType.ON_UPDATE].
* @param modelType the model class.
* @param authMode The [AuthorizationType] to use for making the request
* @param includes lambda returning list of relationships that should be included in the selection set
* @param <M> the concrete type of the model.
* @param <P> the concrete model path for the M model type
* @return a valid [GraphQLRequest] instance.
* @see .of
</M> */
*/
@JvmStatic
fun <M : Model, P : ModelPath<M>> onUpdate(
modelType: Class<M>,
authMode: AuthorizationType,
includes: ((P) -> List<PropertyContainerPath>)
): GraphQLRequest<M> {
return of(modelType, SubscriptionType.ON_UPDATE, includes)
}
): GraphQLRequest<M> = of(modelType, SubscriptionType.ON_UPDATE, authMode, includes)
}
Loading