Skip to content
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

GraphQL Transformer issue when using custom @key and @connection #3702

Closed
drochetti opened this issue Mar 19, 2020 · 4 comments
Closed

GraphQL Transformer issue when using custom @key and @connection #3702

drochetti opened this issue Mar 19, 2020 · 4 comments
Assignees
Labels
bug Something isn't working graphql-transformer-v1 Issue related to GraphQL Transformer v1

Comments

@drochetti
Copy link
Contributor

Problem:

When defining schemas with custom keys, or explicit keys defined along with a field with a @connection directive, the GraphQL transformer expects that the input object of a mutation provide both the id/key and the connected type Input.

Example:

  • Given the following schema
type Post @model {
    id: ID!
    title: String!
    editors: [PostEditor] @connection(keyName: "byPost", fields: ["id"])
}

# Create a join model and disable queries as you don't need them
# and can query through Post.editors and User.posts
type PostEditor
    @model(queries: null)
    @key(name: "byPost", fields: ["postID", "editorID"])
    @key(name: "byEditor", fields: ["editorID", "postID"]) {
    id: ID!
    postID: ID!
    editorID: ID!
    post: Post! @connection(fields: ["postID"])
    editor: User! @connection(fields: ["editorID"])
}

type User @model {
    id: ID!
    username: String!
    posts: [PostEditor] @connection(keyName: "byEditor", fields: ["id"])
}
  • The GraphQL transformer generates the following input for PostEditor:
input PostEditorInput {
	id: ID!
	postID: ID!
	editorID: ID!
	post: PostInput!
}

# ps: omitting the conflict resolution fields _version, _deleted, _lastChangedAt
# since they are not relevant to this issue

A few notes from the generated input:

  1. postID accounts for the connection between Post and PostEditor, so I believe post: PostInput! should not be there, regardless of it's optional or not, given that cascade writes are not supported as of now (is that a fair assumption?)
  2. editorID is there, but editor: UserInput! is not, which seems inconsistent given how postID and post: PostInput! was handled
  3. In a scenario where postID and editorID were not explicitly defined, I would expect the input to have postEditorPostId and postEditorUserId automatically generated, but in no scenario post: PostInput! should be there. Is that correct?

Scenario 1: Customs keys

The expected transformed input is:

input PostEditorInput {
	id: ID!
	postID: ID!
	editorID: ID!
}

Scenario 2: Connections with no custom keys

The expected transformed input is:

input PostEditorInput {
	id: ID!
	postEditorPostId: ID!
	postEditorUserId: ID!
}

Possible related issues:

@yuth yuth added graphql-transformer-v1 Issue related to GraphQL Transformer v1 bug Something isn't working labels Mar 19, 2020
@yuth
Copy link
Contributor

yuth commented Mar 19, 2020

1. `postID` accounts for the connection between `Post` and `PostEditor`, so I believe `post: PostInput!` should not be there, regardless of it's optional or not, given that cascade writes are not supported as of now (is that a fair assumption?)

Yes this is a bug in the graphql-transformer

3\. In a scenario where `postID` and `editorID` were not explicitly defined, I would expect the input to have `postEditorPostId` and `postEditorUserId` automatically generated, but in no scenario `post: PostInput!` should be there. Is that correct?

Yes, This should work when using named connections. When using @connection with fields those fields have to be explicitly defined in the type

@undefobj
Copy link
Contributor

Duplicate of #3438

@undefobj undefobj marked this as a duplicate of #3438 Apr 24, 2020
@kaustavghosh06 kaustavghosh06 removed the pending-response Issue is pending response from the issue author label Apr 24, 2020
@attilah
Copy link
Contributor

attilah commented May 5, 2020

Closing in favor of #3438

@attilah attilah closed this as completed May 5, 2020
@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working graphql-transformer-v1 Issue related to GraphQL Transformer v1
Projects
None yet
Development

No branches or pull requests

6 participants