import { CodeGenDirective , CodeGenField , CodeGenModel , CodeGenModelMap } from '../visitors/appsync-visitor' ; import { CodeGenConnectionType , CodeGenFieldConnection , makeConnectionAttributeName , } from './process-connections' ; import { getConnectedFieldV2 } from './process-connections-v2' ; export function processHasOneConnection ( field , model , modelMap , connectionDirective ) { const otherSide = modelMap [ field . type ] ; const otherSideField = getConnectedFieldV2 ( field , model , otherSide , connectionDirective . name ) ; const connectionFields = connectionDirective . arguments . fields || [ ] ; const isConnectingFieldAutoCreated = connectionFields . length === 0 ; if ( ! field . isList && ! otherSideField . isList ) { return { kind : CodeGenConnectionType . HAS_ONE , associatedWith : otherSideField , connectedModel : otherSide , isConnectingFieldAutoCreated , targetName : connectionFields [ 0 ] || makeConnectionAttributeName ( model . name , field . name ) , } ; } else { throw new Error ( "A hasOne relationship should be 1:1, no lists" ) ; } }