amazon-web-servicesgraphqlaws-appsyncaws-amplify-clivtl

Unknown type FieldUnion for field fields. Did you forget to add the @model directive. Grapghql


getting below error during amplify publish . Unknown type FieldUnion for field fields. Did you forget to add the @model directive the code:

FieldUnion = KeyValueField | AnotherFieldType

type MyObject {
  id: ID!
  fields: [FieldUnion !]
}
interface Field { its definition here}

type KeyValueField  implements Field {
  name: String!
  value: String
}

type AnotherFieldType implements Field {
  label: String!
  content: String!
}

There is a single schema.grapghql file . All Resolvers return __typename with some concrete type of union. This union is never used as input in any mutation. amplify cli version was upgraded to 12.14.4 after which this started coming . we dont use @model anywhere . We have AppSync setup that uses Lambda resolvers and no DynamoDB used behind. Lambda talks to DB.


Solution

  • Can you try basic graphql schema like below

    issue can be at The union FieldUnion = KeyValueField | AnotherFieldType which likely must come after the types it references

    interface Field {
      # Add your field definition here
    }
    
    type KeyValueField implements Field {
      name: String!
      value: String
    }
    
    type AnotherFieldType implements Field {
      label: String!
      content: String!
    }
    
    union FieldUnion = KeyValueField | AnotherFieldType
    
    type MyObject {
      id: ID!
      fields: [FieldUnion!]
    }
    

    This will be resolves the "Unknown type FieldUnion" error and it will check for ensuring proper GraphQL type definition order that Amplify CLI this now strictly checks the syntax