Amplify-cli: Generated Swift API does not contain correct nested Entities in GQL Query

Created on 13 Nov 2018  路  3Comments  路  Source: aws-amplify/amplify-cli

Describe the bug
When generating the Swift SDK from my graphql schema, subentities on an entity do not have all their fields in the generated query string inside the created API file.

To Reproduce
Steps to reproduce the behavior:

  1. Go to AppSync Console
  2. Create new API with this schema
    ````
    type Event {
    id: ID!
    version: Int!
    label: String!
    code: String!
    avatar: AWSURL
    phone: String
    }

type Member {
id: ID!
version: Int!
label: String
avatar: AWSURL
phone: String!
}

type Moment {
id: ID!
version: Int!
status: String!
from: Participation!
event: Event!
featuredTag: String
tags: [String!]
caption: String
photo: AWSURL
fallback: AWSURL
quote: String
background: AWSURL
}

input MomentFilterInput {
event: ID
member: ID
participation: ID
featuredTag: String
tags: [String!]
status: [String!]
}

type Participation {
id: ID!
version: Int!
member: Member!
event: Event!
role: String!
designation: String
status: String!
}

type Query {
getMoment(id: ID!): Moment
listMoments(filter: MomentFilterInput): [Moment!]
}

schema {
query: Query
}
````

  1. Create an amplify project
  2. run amplify add codegen --apiId 123TheApiKey
  3. Look at the query string of the ListMomentsQuery below (formatted for readability)
    ````
    public final class ListMomentsQuery: GraphQLQuery {
    public static let operationString =
    "query ListMoments($filter: MomentFilterInput) {
    listMoments(filter: $filter) {
    __typename
    id
    version
    status
    from {
    __typename
    id
    version
    role ##This is missing member and member's subfields
    designation
    status
    }
    event {
    __typename
    id
    version
    label
    code
    avatar
    phone
    }
    featuredTag
    tags
    caption
    photo
    fallback
    quote
    background
    }
    }"

....
````

Expected behavior
I expected that in the above query string I would see the member field on a participation (the from ).

This is a pretty major problem because it means I can only have entities that are very shallow OR I have to do all the bookkeeping of ID referencing myself. Am I misunderstanding how to use the API here?

code-gen enhancement

Most helpful comment

Is this two step process documented somewhere? I almost gave up on appsync entirely because of this issue and after scouring the documentation for well over 2 days I filed this issue because I couldn't figure out why it was behaving like this.

To be clear, I'm thrilled there is a known solution here, I just hope more folks find this issue rather than give up like I almost did. Thank you for your help.

All 3 comments

@MageMasher amplify codegen by default limits the number level it traverses in response type. This is done to prevent an infinite loop if a type refers to itself. We don't have a way to change the depth using CLI, but we might implement a way to pass that in the future.

amplify codegen is 2 step process

  1. Statement generation - takes a schema and generates statements. Its here we have limit on the levels.
  2. types generation - takes the schema and statements and generate swift or typescript files.

So to solve the issue you have you could update the statements generated in step 1. The files are located inside <proj-directory>/graphql to include members subfield. After doing that make sure say no to Do you want to generate/update all possible GraphQL operations - queries, mutations and subscriptions and the generated code will have memebers.

Is this two step process documented somewhere? I almost gave up on appsync entirely because of this issue and after scouring the documentation for well over 2 days I filed this issue because I couldn't figure out why it was behaving like this.

To be clear, I'm thrilled there is a known solution here, I just hope more folks find this issue rather than give up like I almost did. Thank you for your help.

Is this two step process documented somewhere? I almost gave up on appsync entirely because of this issue and after scouring the documentation for well over 2 days I filed this issue because I couldn't figure out why it was behaving like this.

No its not documented anywhere. I have created an https://github.com/aws-amplify/docs/issues/199 in our documentation repo.

Was this page helpful?
0 / 5 - 0 ratings