@aws-amplify/data-schema
Advanced tools
Comparing version 0.12.9 to 0.12.10
@@ -6,4 +6,5 @@ import { SetTypeSubArg, Brand } from '@aws-amplify/data-schema-types'; | ||
import { EnumType, EnumTypeParamShape } from './EnumType'; | ||
import { CustomType } from './CustomType'; | ||
type CustomArguments = Record<string, ModelField<any, any> | EnumType<EnumTypeParamShape>>; | ||
type CustomReturnType = RefType<any>; | ||
type CustomReturnType = RefType<any> | CustomType<any>; | ||
type CustomFunctionRefType = string; | ||
@@ -10,0 +11,0 @@ type InternalCustomArguments = Record<string, InternalField>; |
@@ -10,6 +10,6 @@ import { Brand } from '@aws-amplify/data-schema-types'; | ||
export type CustomTypeAllowedModifiers = 'authorization' | 'array' | 'required'; | ||
type ModelFields = Record<string, ModelField<ModelFieldTypeParamOuter, CustomTypeAllowedModifiers, any>>; | ||
type CustomTypeFields = Record<string, ModelField<ModelFieldTypeParamOuter, CustomTypeAllowedModifiers, any>>; | ||
type InternalModelFields = Record<string, InternalField>; | ||
type CustomTypeData = { | ||
fields: ModelFields; | ||
fields: CustomTypeFields; | ||
type: 'customType'; | ||
@@ -21,3 +21,3 @@ }; | ||
export type CustomTypeParamShape = { | ||
fields: ModelFields; | ||
fields: CustomTypeFields; | ||
}; | ||
@@ -32,5 +32,5 @@ export type CustomType<T extends CustomTypeParamShape> = Brand<T, 'customType'>; | ||
}; | ||
export declare function customType<T extends ModelFields>(fields: T): CustomType<{ | ||
export declare function customType<T extends CustomTypeFields>(fields: T): CustomType<{ | ||
fields: T; | ||
}>; | ||
export {}; |
@@ -115,13 +115,26 @@ "use strict"; | ||
const { arguments: fieldArgs, returnType, authorization, functionRef, } = typeDef.data; | ||
let callSignature = typeName; | ||
const implicitModels = []; | ||
const { authString } = calculateAuth(authorization); | ||
const resolvedArg = refFieldToGql(returnType.data); | ||
let sig = typeName; | ||
let implicitModels = []; | ||
let returnTypeName; | ||
if (isRefField(returnType)) { | ||
returnTypeName = refFieldToGql(returnType.data); | ||
} | ||
else if (isCustomType(returnType)) { | ||
returnTypeName = `${capitalize(typeName)}ReturnType`; | ||
implicitModels.push([returnTypeName, returnType]); | ||
} | ||
else if (isScalarField(returnType)) { | ||
returnTypeName = scalarFieldToGql(returnType.data); | ||
} | ||
else { | ||
throw new Error(`Unrecognized return type on ${typeName}`); | ||
} | ||
if (Object.keys(fieldArgs).length > 0) { | ||
const { gqlFields, models } = processFields(fieldArgs, {}); | ||
sig += `(${gqlFields.join(', ')})`; | ||
implicitModels = models; | ||
callSignature += `(${gqlFields.join(', ')})`; | ||
implicitModels.push(...models); | ||
} | ||
const fnString = functionRef ? `@function(name: "${functionRef}") ` : ''; | ||
const gqlField = `${sig}: ${resolvedArg} ${fnString}${authString}`; | ||
const gqlField = `${callSignature}: ${returnTypeName} ${fnString}${authString}`; | ||
return { gqlField, models: implicitModels }; | ||
@@ -128,0 +141,0 @@ } |
{ | ||
"name": "@aws-amplify/data-schema", | ||
"version": "0.12.9", | ||
"version": "0.12.10", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
202943
2628