Describe the bug
I have defined the following in amplify/backend/api/{name of api}/schema.graphql:
type InventoryItem
@model(queries: { get: "inventoryItem" }, mutations: null)
@auth(rules: [{ allow: owner }]) {
id: ID!
description: String!
mood: String
}
type Inventory @model @auth(rules: [{ allow: owner }]) {
id: ID!
items: [InventoryItem]! @connection
}
Which compiles to the following with amplify api gql-compile:
type InventoryItem {
id: ID!
description: String!
mood: String
}
type Inventory {
id: ID!
items(filter: ModelInventoryItemFilterInput, sortDirection: ModelSortDirection, limit: Int, nextToken: String): ModelInventoryItemConnection
}
type Query {
inventoryItem(id: ID!): InventoryItem
getInventory(id: ID!): Inventory
listInventorys(filter: ModelInventoryFilterInput, limit: Int, nextToken: String): ModelInventoryConnection
}
input CreateInventoryItemInput {
description: String!
mood: String
inventoryItemsId: ID
}
input UpdateInventoryItemInput {
id: ID!
description: String
mood: String
inventoryItemsId: ID
}
input DeleteInventoryItemInput {
id: ID
}
type Mutation {
createInventory(input: CreateInventoryInput!): Inventory
updateInventory(input: UpdateInventoryInput!): Inventory
deleteInventory(input: DeleteInventoryInput!): Inventory
}
type Subscription {
onCreateInventory: Inventory @aws_subscribe(mutations: ["createInventory"])
onUpdateInventory: Inventory @aws_subscribe(mutations: ["updateInventory"])
onDeleteInventory: Inventory @aws_subscribe(mutations: ["deleteInventory"])
}
enum ModelSortDirection {
ASC
DESC
}
type ModelInventoryConnection {
items: [Inventory]
nextToken: String
}
input ModelStringFilterInput {
ne: String
eq: String
le: String
lt: String
ge: String
gt: String
contains: String
notContains: String
between: [String]
beginsWith: String
}
input ModelIDFilterInput {
ne: ID
eq: ID
le: ID
lt: ID
ge: ID
gt: ID
contains: ID
notContains: ID
between: [ID]
beginsWith: ID
}
input ModelIntFilterInput {
ne: Int
eq: Int
le: Int
lt: Int
ge: Int
gt: Int
contains: Int
notContains: Int
between: [Int]
}
input ModelFloatFilterInput {
ne: Float
eq: Float
le: Float
lt: Float
ge: Float
gt: Float
contains: Float
notContains: Float
between: [Float]
}
input ModelBooleanFilterInput {
ne: Boolean
eq: Boolean
}
input ModelInventoryFilterInput {
id: ModelIDFilterInput
and: [ModelInventoryFilterInput]
or: [ModelInventoryFilterInput]
not: ModelInventoryFilterInput
}
input CreateInventoryInput
input UpdateInventoryInput {
id: ID!
}
input DeleteInventoryInput {
id: ID
}
type ModelInventoryItemConnection {
items: [InventoryItem]
nextToken: String
}
input ModelInventoryItemFilterInput {
id: ModelIDFilterInput
description: ModelStringFilterInput
mood: ModelStringFilterInput
and: [ModelInventoryItemFilterInput]
or: [ModelInventoryItemFilterInput]
not: ModelInventoryItemFilterInput
}
You notice that CreateInventoryInput doesn't have any attributes, which appears to cause this to fail when attempting amplify api push.
To Reproduce
Steps to reproduce the behavior:
amplify api pushCREATE_FAILED GraphQLSchema AWS::AppSync::GraphQLSchema Wed Oct 03 2018 12:08:45 GMT-0400 (EDT) Schema Creation Status is FAILED with details: Failed to parse schema document - ensure it's a valid SDL-formatted document.
Expected behavior
Expected the schema to be compiled to a valid document. On amplify api push should create resources as defined and make the API available.
Desktop (please complete the following information):
This actually appears to be my error, proper schema below:
type Inventory @model @auth(rules: [{ allow: owner }]) {
id: ID!
date: String!
items: [InventoryItem] @connection
}
type InventoryItem @model @auth(rules: [{ allow: owner }]) {
id: ID!
description: String!
mood: String
}
Wasn't immediately clear that Inventory needed a field outside of id to create the input type.
I was going insane and this post saved me. Thank you @wmcbain !
It would be very useful if Amplify api gql-compile caught that issue, I spent a longtime trying different things and each time having to push changes, then wait several minutes to troubleshoot
@wmcbain @azahran007 Hi guys, i have the sae problem.
Can you please explain more what is wrong?
@tmjordan when creating your schema, you can't have just the id field and other relationship fields. You need to have at least one other regular field. In the example above, adding field date: String! to the Inventory type solves the problem.
@azahran007 thank you very much man :)
Most helpful comment
@tmjordan when creating your schema, you can't have just the
idfield and other relationship fields. You need to have at least one other regular field. In the example above, adding fielddate: String!to the Inventory type solves the problem.