Amplify-cli: The schema generated by amplify api gql-compile is not correct

Created on 7 Jan 2020  ยท  8Comments  ยท  Source: aws-amplify/amplify-cli

  1. Edit amplify/backend/api/xxxx/schema.graphql
type Advertisement @model(mutations: null, subscriptions: null){
  productID: ID!
  productDescription: String
  redPackets: [SharedRedPacket] @connection(name: "AdsRPs")
}

type User @model(mutations: null, subscriptions: null) {
  userEmail: ID!
  balance: Float
  hasSharedRP: Boolean
  city: String
}

type SharedRedPacket @model(mutations: null, subscriptions: null) {
  userEmail: ID!
  advertisement: Advertisement @connection(name: "AdsRPs")
  sharedDoneFlag: Boolean
  sharedDetails: [SharedDetail]
}

type SharedDetail {
  userEmail: String!
  value: Float!
}
  1. Run amplify api gql-compile, and the schema is generated
  2. The following is the generated amplify/backend/api/xxx/build/schema.graphql
type Advertisement {
  productID: ID!
  productDescription: String
  redPackets(filter: ModelSharedRedPacketFilterInput, sortDirection: ModelSortDirection, limit: Int, nextToken: String): ModelSharedRedPacketConnection
}

type User {
  userEmail: ID!
  balance: Float
  hasSharedRP: Boolean
  city: String
}

type SharedRedPacket {
  userEmail: ID!
  advertisement: Advertisement
  sharedDoneFlag: Boolean
  sharedDetails: [SharedDetail]
}

type SharedDetail {
  userEmail: String!
  value: Float!
}

enum ModelSortDirection {
  ASC
  DESC
}

type ModelAdvertisementConnection {
  items: [Advertisement]
  nextToken: String
}

input ModelStringInput {
  ne: String
  eq: String
  le: String
  lt: String
  ge: String
  gt: String
  contains: String
  notContains: String
  between: [String]
  beginsWith: String
  attributeExists: Boolean
  attributeType: ModelAttributeTypes
  size: ModelSizeInput
}

input ModelIDInput {
  ne: ID
  eq: ID
  le: ID
  lt: ID
  ge: ID
  gt: ID
  contains: ID
  notContains: ID
  between: [ID]
  beginsWith: ID
  attributeExists: Boolean
  attributeType: ModelAttributeTypes
  size: ModelSizeInput
}

input ModelIntInput {
  ne: Int
  eq: Int
  le: Int
  lt: Int
  ge: Int
  gt: Int
  between: [Int]
  attributeExists: Boolean
  attributeType: ModelAttributeTypes
}

input ModelFloatInput {
  ne: Float
  eq: Float
  le: Float
  lt: Float
  ge: Float
  gt: Float
  between: [Float]
  attributeExists: Boolean
  attributeType: ModelAttributeTypes
}

input ModelBooleanInput {
  ne: Boolean
  eq: Boolean
  attributeExists: Boolean
  attributeType: ModelAttributeTypes
}

input ModelSizeInput {
  ne: Int
  eq: Int
  le: Int
  lt: Int
  ge: Int
  gt: Int
  between: [Int]
}

input ModelAdvertisementFilterInput {
  productID: ModelIDInput
  productDescription: ModelStringInput
  and: [ModelAdvertisementFilterInput]
  or: [ModelAdvertisementFilterInput]
  not: ModelAdvertisementFilterInput
}

type Query {
  getAdvertisement(id: ID!): Advertisement
  listAdvertisements(filter: ModelAdvertisementFilterInput, limit: Int, nextToken: String): ModelAdvertisementConnection
  getUser(id: ID!): User
  listUsers(filter: ModelUserFilterInput, limit: Int, nextToken: String): ModelUserConnection
  getSharedRedPacket(id: ID!): SharedRedPacket
  listSharedRedPackets(filter: ModelSharedRedPacketFilterInput, limit: Int, nextToken: String): ModelSharedRedPacketConnection
}

type ModelUserConnection {
  items: [User]
  nextToken: String
}

input ModelUserFilterInput {
  userEmail: ModelIDInput
  balance: ModelFloatInput
  hasSharedRP: ModelBooleanInput
  city: ModelStringInput
  and: [ModelUserFilterInput]
  or: [ModelUserFilterInput]
  not: ModelUserFilterInput
}

input SharedDetailInput {
  userEmail: String!
  value: Float!
}

type ModelSharedRedPacketConnection {
  items: [SharedRedPacket]
  nextToken: String
}

input ModelSharedRedPacketFilterInput {
  userEmail: ModelIDInput
  sharedDoneFlag: ModelBooleanInput
  and: [ModelSharedRedPacketFilterInput]
  or: [ModelSharedRedPacketFilterInput]
  not: ModelSharedRedPacketFilterInput
}
  1. Run amplify push
  2. Got error message
The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelStringInput' [@73:1].
The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelIDInput' [@89:1].
The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelIntInput' [@105:1].
The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelFloatInput' [@117:1].
The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelBooleanInput' [@129:1].

The generated schema file is obviously wrong, it does not have ModelAttributeTypes defined.

Amplify CLI Version
4.10.0

Desktop (please complete the following information):

  • OS: MAC
  • Node Version. v12.13.1
bug graphql-transformer

Most helpful comment

@isheejong Are you using the latest version of the CLI (4.18.1)? The fix mentioned above is available in that release.

All 8 comments

@JoeShi taking a look

@ammarkarachi do we have any update?

I added brand new type/model to existing schema and amplify push didn't update graphql mutation and queries.

So I tried amplify api gql-compile and same again. Nothing was changed.

amplify codegen models did update model based on new schema.

amplify cli v4.17.2

Solved by using amplify codgen

I have also encountered same problem.
`Resource Name: zaic7uucg5fcjnuysj35hs4ba4GraphQLSchema (AWS::AppSync::GraphQLSchema)
Event Type: update

Reason: Schema Creation Status is FAILED with details: Found 6 problem(s) with the schema:
The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelStringInput' [@151:1].

The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelIDInput' [@167:1].
The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelIntInput' [@183:1].

The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelFloatInput' [@195:1].

The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelBooleanInput' [@207:1].

The input value type 'ModelPRODUCT_TYPEInput' is not present when resolving type 'ModelCartItemFilterInput' [@224:1].`

@isheejong Are you using the latest version of the CLI (4.18.1)? The fix mentioned above is available in that release.

@isheejong Are you using the latest version of the CLI (4.18.1)? The fix mentioned above is available in that release.

Here is my version of amplify CLI used

[email protected]:~/environment $ amplify -v
4.18.1

and this is schema.graphql for generations.

type Cart 
@model(queries: null, mutations: null, subscriptions: null)
@aws_api_key
@aws_cognito_user_pools
@key( fields : ["sessionId"], name: "sessionId")
{
  id : ID!
  memberId:String
  sessionId: ID
  cartType: CART_TYPE!
  cartName: String!
  orderSummary: AWSJSON
  orderSummaryInfo: AWSJSON 
  createTime: AWSDateTime
  updateTime: AWSDateTime
  cartItems: [CartItem] @connection(name:"CartCartItem")
}

type CartItem 
@model(queries: null, mutations: null, subscriptions: null)
@aws_api_key
@aws_cognito_user_pools
{
  id: ID!
  productNo: String!
  itemNo: String!
  productType: PRODUCT_TYPE! 
  packageNo: String!
  sellerId: String!
  productName: String! 
  itemName: String!
  itemPrice: Float! 
  itemQty: Float! 
  cartItemInfo: AWSJSON 
  cart: Cart @connection(name:"CartCartItem")
}

enum CART_TYPE {
  MEMBER
  SESSION
}

enum PRODUCT_TYPE {
  UNIT
  PACKAGE
}

type Query {
  getMyCart:Cart
  getCartBySessionId(sessionId:String!):Cart
}

input CreateCartInput{
  cartType: CART_TYPE!
  cartName: String!
  orderSummary: AWSJSON
  orderSummaryInfo: AWSJSON
}

input UpdateMyCartInput{
  memberId: String!
  orderSummary: AWSJSON
  orderSummaryInfo: AWSJSON
}

input UpdateCartInputBySessionId{
  sessionId: String!
  orderSummary: AWSJSON
  orderSummaryInfo: AWSJSON
}

type Mutation{

  createCart(input: CreateCartInput!):Cart
  @aws_cognito_user_pools
  @aws_api_key

  updateMyCart(input: UpdateMyCartInput!):Cart
  @aws_cognito_user_pools

  updateCartBySessionId(input: UpdateCartInputBySessionId!):Cart
  @aws_api_key

}
-----------------------------------------------------------------
Resource Name: zaic7uucg5fcjnuysj35hs4ba4GraphQLSchema (AWS::AppSync::GraphQLSchema)
Event Type: update
Reason: Schema Creation Status is FAILED with details: Found 6 problem(s) with the schema:
The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelStringInput' [@151:1].
The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelIDInput' [@167:1].
The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelIntInput' [@183:1].
The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelFloatInput' [@195:1].
The input value type 'ModelAttributeTypes' is not present when resolving type 'ModelBooleanInput' [@207:1].
The input value type 'ModelPRODUCT_TYPEInput' is not present when resolving type 'ModelCartItemFilterInput' [@224:1].
URL: https://console.aws.amazon.com/cloudformation/home?region=ap-northeast-2#/stacks/arn%3Aaws%3Acloudformation%3Aap-northeast-2%3A786923391258%3Astack%2Famplify-kestore-heejong-25054-apikestore-Y8NY1TR62L19%2F48c738a0-85d7-11ea-ab05-06ad40dfc020/events
-------------------------------------------------------



md5-c36bfe16123d4252c7e2db55aefe96c8



[email protected]:~/environment/korea-ecommerce-store (master) $ amplify codegen models
The following types do not have '@auth' enabled. Consider using @auth with @model
         - Cart
         - CartItem
Learn more about @auth here: https://aws-amplify.github.io/docs/cli-toolchain/graphql#auth 
GraphQL schema compiled successfully.

I'm out of idea how to resolve that problem. :)
Are there any problem in schema or need to correct the schema ?

Hi there

Thank you for interesting my problem. I 'm working on developing e-commerce
site with customer.
I have replied from your comment, could you check my comment?

Thank you
Heeejong

2020๋…„ 4์›” 25์ผ (ํ† ) ์˜ค์ „ 1:09, Edward Foyle notifications@github.com๋‹˜์ด ์ž‘์„ฑ:

@isheejong https://github.com/isheejong Are you using the latest
version of the CLI (4.18.1)? The fix mentioned above is available in that
release.

โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/aws-amplify/amplify-cli/issues/3141#issuecomment-619104169,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ADZ77HFGCZGLQD7OZT3MH6TROG2SPANCNFSM4KD2GWOQ
.

--

[email protected]
Best Regards
HeeJong

following up in #4081

Was this page helpful?
0 / 5 - 0 ratings