Amplify-cli: Compiled GraphQL does not appear to valid and amplify api push fails.

Created on 3 Oct 2018  路  5Comments  路  Source: aws-amplify/amplify-cli

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:

  1. With the following schema try amplify api push
  2. Should fail with the following error and trigger a rollback.
CREATE_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):

  • OS: Mac OS X 10.14
  • Version 0.1.24 & 0.1.27 tested

Most helpful comment

@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.

All 5 comments

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 :)

Was this page helpful?
0 / 5 - 0 ratings