@aws-amplify/data-schema 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/ModelType.ts CHANGED
@@ -259,7 +259,7 @@ export type ModelType<
259
259
  Brand<typeof brandName>;
260
260
 
261
261
  /**
262
- * External representation of Model Type that exposes the `addRelationships` modifier.
262
+ * External representation of Model Type that exposes the `relationships` modifier.
263
263
  * Used on the complete schema object.
264
264
  */
265
265
  export type SchemaModelType<
@@ -271,7 +271,7 @@ export type SchemaModelType<
271
271
  IsRDS extends boolean = false,
272
272
  > = IsRDS extends true
273
273
  ? T & {
274
- addRelationships<
274
+ relationships<
275
275
  Param extends Record<
276
276
  string,
277
277
  ModelRelationalField<any, string, any, any>
@@ -329,7 +329,7 @@ function _model<T extends ModelTypeParamShape>(fields: T['fields']) {
329
329
  return {
330
330
  ...builder,
331
331
  data,
332
- addRelationships(relationships) {
332
+ relationships(relationships) {
333
333
  data.fields = { ...data.fields, ...relationships };
334
334
  },
335
335
  fields: data.fields,
@@ -352,7 +352,7 @@ export const isSchemaModelType = (
352
352
  internalType.data.authorization !== undefined &&
353
353
  internalType.data.identifier !== undefined &&
354
354
  internalType.data.secondaryIndexes !== undefined &&
355
- typeof internalType.addRelationships === 'function'
355
+ typeof internalType.relationships === 'function'
356
356
  );
357
357
  };
358
358
 
@@ -678,6 +678,11 @@ export function generateGraphQLDocument(
678
678
  },
679
679
  } = modelDefinition;
680
680
 
681
+ // Use pascal case of the model name to generate the operations and the arguments.
682
+ // This is required to be in sync with the resources generated by the GraphQL transformers.
683
+ const namePascalCase = name.charAt(0).toUpperCase() + name.slice(1);
684
+ const pluralNamePascalCase = pluralName.charAt(0).toUpperCase() + pluralName.slice(1);
685
+
681
686
  const { operationPrefix, usePlural } = graphQLOperationsInfo[modelOperation];
682
687
 
683
688
  const { selectionSet } = listArgs || {};
@@ -686,7 +691,7 @@ export function generateGraphQLDocument(
686
691
  let indexQueryArgs: Record<string, string>;
687
692
 
688
693
  if (operationPrefix) {
689
- graphQLFieldName = `${operationPrefix}${usePlural ? pluralName : name}`;
694
+ graphQLFieldName = `${operationPrefix}${usePlural ? pluralNamePascalCase : namePascalCase}`;
690
695
  } else if (indexMeta) {
691
696
  const { queryField, pk, sk = [] } = indexMeta;
692
697
  graphQLFieldName = queryField;
@@ -775,7 +780,7 @@ export function generateGraphQLDocument(
775
780
  input: `${
776
781
  operationPrefix.charAt(0).toLocaleUpperCase() +
777
782
  operationPrefix.slice(1)
778
- }${name}Input!`,
783
+ }${namePascalCase}Input!`,
779
784
  });
780
785
  graphQLOperationType ?? (graphQLOperationType = 'mutation');
781
786
  // TODO(Eslint): this this case clause correct without the break statement?
@@ -795,7 +800,7 @@ export function generateGraphQLDocument(
795
800
  // ignore the eslint error on the ts-ignore.
796
801
  // eslint-disable-next-line
797
802
  // @ts-ignore
798
- filter: `Model${name}FilterInput`,
803
+ filter: `Model${namePascalCase}FilterInput`,
799
804
  limit: 'Int',
800
805
  nextToken: 'String',
801
806
  });
@@ -808,7 +813,7 @@ export function generateGraphQLDocument(
808
813
  graphQLArguments ??
809
814
  (graphQLArguments = {
810
815
  ...indexQueryArgs!,
811
- filter: `Model${name}FilterInput`,
816
+ filter: `Model${namePascalCase}FilterInput`,
812
817
  sortDirection: 'ModelSortDirection',
813
818
  limit: 'Int',
814
819
  nextToken: 'String',
@@ -823,7 +828,7 @@ export function generateGraphQLDocument(
823
828
  case 'ONDELETE':
824
829
  graphQLArguments ??
825
830
  (graphQLArguments = {
826
- filter: `ModelSubscription${name}FilterInput`,
831
+ filter: `ModelSubscription${namePascalCase}FilterInput`,
827
832
  });
828
833
  graphQLOperationType ?? (graphQLOperationType = 'subscription');
829
834
  graphQLSelectionSet ?? (graphQLSelectionSet = selectionSetFields);