Skip to content

ampify codegen model filters out connection fields #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TheDutchCoder opened this issue Jan 13, 2021 · 4 comments
Open

ampify codegen model filters out connection fields #214

TheDutchCoder opened this issue Jan 13, 2021 · 4 comments
Labels
bug Something isn't working p2 type-gen Issues on graphql-type-generator

Comments

@TheDutchCoder
Copy link

Describe the bug
When you have a connection field in your schema, like this:

type Order
  @model(subscriptions: null)
  @key(name: "ByCustomer", fields: ["customerID"], queryField: "ordersByCustomer")
{
  id: ID!
  businessID: ID!
  customerID: ID!
  customer: Customer @connection(fields: ["customerID"])
}

The generated models do not include the customerID property and instead nest it under customer.business.id because it maps business to be of type Business.

This is technically not "wrong", but the result still very much includes customerID when queries and now the models don't line up anymore. Reading the result as customer.business.id probably works, but it's not the most efficient.

Amplify CLI Version
4.41.1

To Reproduce
Create a schema with a connection field.
Run codegen for models.
See the property is missing.

Expected behavior
Property to still be included.

Screenshots
Missing property in the models.
image

TS error when using the model
image

Desktop (please complete the following information):

  • OS: MacOS 10.15.7
  • Node Version. 12.19.0
@attilah
Copy link
Contributor

attilah commented Jan 14, 2021

@TheDutchCoder could you share the complete schema and the use case you try to achieve to be able to help you better? From this partial information it is harder to see what you try to do, beside that modelgen generated code is not "optimal", but I suspect that maybe the model could be change if we know what are the goals.

@TheDutchCoder
Copy link
Author

TheDutchCoder commented Jan 14, 2021

I can't really give the whole schema, it's quite big, but I'll give you all related things for the one model:

Model

type UserInvite
  @model(subscriptions: null)
  @key(name: "invitationsByBusiness", fields: ["businessID","id"], queryField: "invitationsByBusiness")
  @key(name: "invitationsByEmail", fields: ["email","id"], queryField: "invitationsByEmail")
{
  id: ID!
  businessID: ID!
  email: String!
  role: UserRole!
  business: Business @connection(fields: ["businessID"])
  status: UserInviteStatus!
  createdAt: AWSDateTime!
}

Subscriptions

type Subscription {
	onCreateUserInvite(businessID: ID): UserInvite
		@aws_subscribe(mutations: ["createUserInvite"])
	onUpdateUserInvite(businessID: ID): UserInvite
		@aws_subscribe(mutations: ["updateUserInvite"])
	onDeleteUserInvite(businessID: ID): UserInvite
		@aws_subscribe(mutations: ["deleteUserInvite"])

	onCreateUserInviteEmail(email: String): UserInvite
		@aws_subscribe(mutations: ["createUserInvite"])
	onUpdateUserInviteEmail(email: String): UserInvite
		@aws_subscribe(mutations: ["updateUserInvite"])
	onDeleteUserInviteEmail(email: String): UserInvite
		@aws_subscribe(mutations: ["deleteUserInvite"])
}

Enum

enum UserInviteStatus {
	pending
	accepted
	rejected
}

Query

export const getUserInvite = /* GraphQL */ `
  query GetUserInvite($id: ID!) {
    getUserInvite(id: $id) {
      id
      businessID
      email
      role
      business {
        id
        name
        slug
        owner
        users {
          items {
            id
            businessID
            name
            initials
            email
            role
            active
            business {
              id
              name
              slug
              owner
              createdAt
              updatedAt
            }
            createdAt
            updatedAt
          }
          nextToken
        }
        createdAt
        updatedAt
      }
      status
      createdAt
      updatedAt
    }
  }
`;

Goal: to get businessID into the model, instead of it being "filtered" out.
As you can see, the query returns businessID, but the model is missing it, which means that TypeScript thinks it doesn't exist on the returned data.

Is that enough to go on?

@kaustavghosh06 kaustavghosh06 transferred this issue from aws-amplify/amplify-cli Aug 6, 2021
@phani-srikar phani-srikar added bug Something isn't working type-gen Issues on graphql-type-generator labels Mar 29, 2022
@alharris-at alharris-at added p3 pending-triage Issues that need further discussion to determine labels Apr 21, 2022
@alharris-at
Copy link
Contributor

We should verify if this is an issue in the v2 transformer version as well.

@alharris-at alharris-at removed the pending-triage Issues that need further discussion to determine label May 10, 2022
@alharris-at alharris-at added pending-triage Issues that need further discussion to determine and removed p3 labels May 10, 2022
@ykethan
Copy link
Member

ykethan commented Jun 22, 2022

linking the following issues for visibility:
#349
#148

@ykethan ykethan added the p2 label Aug 30, 2022
@dpilch dpilch removed the pending-triage Issues that need further discussion to determine label Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p2 type-gen Issues on graphql-type-generator
Projects
None yet
Development

No branches or pull requests

6 participants