File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
packages/amplify-graphql-default-value-transformer/src Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -72,10 +72,21 @@ const validateDefaultValueType = (ctx: TransformerSchemaVisitStepContextProvider
7272 }
7373} ;
7474
75+ const validateNotPrimaryKey = ( field : FieldDefinitionNode ) : void => {
76+ let isPrimaryKeyField =
77+ field . directives ! . find ( ( dir ) => dir . name . value === 'primaryKey' ) ||
78+ ( getBaseType ( field . type ) === 'ID' && field . type . kind === Kind . NON_NULL_TYPE && field . name . value === 'id' ) ;
79+
80+ if ( isPrimaryKeyField ) {
81+ throw new InvalidDirectiveError ( 'The @default directive may not be applied to primaryKey fields.' ) ;
82+ }
83+ } ;
84+
7585const validate = ( ctx : TransformerSchemaVisitStepContextProvider , config : DefaultValueDirectiveConfiguration ) : void => {
7686 validateModelDirective ( config ) ;
7787 validateFieldType ( ctx , config . field . type ) ;
7888 validateDirectiveArguments ( config . directive ) ;
89+ validateNotPrimaryKey ( config . field ) ;
7990
8091 // Validate the default values only for the DynamoDB datasource.
8192 // For SQL, the database determines and sets the default value. We will not validate the value in transformers.
You can’t perform that action at this time.
0 commit comments