这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@rakeshkky
Copy link
Member

Description

Affected components

  • Server

Related Issues

fix #1576

Solution and Design

If returning field contains nested selections then mutation is performed in two steps

  1. Mutation is performed with returning columns of any primary key and unique constraints
  2. returning fields are queried on rows returned by selecting from table by filtering with column values returned in Step 1.

Since mutation takes two courses based on selecting relations in returning field, it is hard to maintain sequence of prepared arguments (PrepArg) generated while resolving returning field. So, we're using txtConverter instead of prepare to resolve mutation fields.

Steps to test and verify

For typical author-article schema:-
Insert an article along with author and query author along with its articles in returning field. It must return inserted article.

Query:-

mutation {
  insert_article(
    objects: [{
      id: 5
      title: "Article by Author 5"
      content: "Content for Article 5"
      author: {
        data: {
          id: 5
          name: "Author 5"
        }
      }
    }]
  ){
    affected_rows
    returning{
      id
      title
      content
      author{
        id
        name
        articles_aggregate{
          aggregate{count}
        }
        articles{
          id
          title
          content
        }
      }
    }
  }
}

Response:-

{
  "data": {
    "insert_article": {
      "affected_rows": 2,
      "returning": [
        {
          "content": "Content for Article 5",
          "author": {
            "name": "Author 5",
            "articles": [
              {
                "content": "Content for Article 5",
                "id": 5,
                "title": "Article by Author 5"
              }
            ],
            "id": 5,
            "articles_aggregate": {
              "aggregate": {
                "count": 1
              }
            }
          },
          "id": 5,
          "title": "Article by Author 5"
        }
      ]
    }
  }
}

Limitations, known bugs & workarounds

Querying relations in returning field of mutation response and Inserting nested objects are strictly available to tables which has atleast one primary key defined or one unique constraints defined on not null columns

Resolve Conflicts:
	server/src-lib/Hasura/GraphQL/Resolve/Insert.hs
	server/src-lib/Hasura/GraphQL/Resolve/Mutation.hs
	server/src-lib/Hasura/RQL/DDL/Schema/Diff.hs
	server/src-lib/Hasura/RQL/DML/Delete.hs
	server/src-lib/Hasura/RQL/DML/Insert.hs
	server/src-lib/Hasura/RQL/DML/QueryTemplate.hs
	server/src-lib/Hasura/RQL/DML/Update.hs
@rakeshkky rakeshkky added s/ok-to-merge Status: This pull request can be merged to master c/server Related to server labels Mar 6, 2019
@rakeshkky rakeshkky self-assigned this Mar 6, 2019
@rakeshkky rakeshkky requested a review from 0x777 March 6, 2019 09:48
@rakeshkky rakeshkky changed the title fix mutation returning query when relationships are present (fix #1576) fix mutation returning when relationships are present (fix #1576) Mar 6, 2019
@hasura-bot
Copy link
Contributor

Review app for commit 8f17d2e deployed to Heroku: https://hge-ci-pull-1703.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1703-8f17d2e

@hasura-bot
Copy link
Contributor

Review app for commit 3cca30e deployed to Heroku: https://hge-ci-pull-1703.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1703-3cca30e

@0x777 0x777 merged commit 5f274b5 into hasura:master Mar 7, 2019
@hasura-bot
Copy link
Contributor

Review app https://hge-ci-pull-1703.herokuapp.com is deleted

hasura-bot pushed a commit that referenced this pull request Mar 5, 2025
also clarified/documented a couple things

### What

<!-- What is this PR trying to accomplish (and why, if it's not
obvious)? -->

<!-- Consider: do we need to add a changelog entry? -->

<!-- Does this PR introduce new validation that might break old builds?
-->

<!-- Consider: do we need to put new checks behind a flag? -->

### How

<!-- How is it trying to accomplish it (what are the implementation
steps)? -->

V3_GIT_ORIGIN_REV_ID: b8b302d5b8d43a466d82f0c8ea3c5443caa70251
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c/server Related to server s/ok-to-merge Status: This pull request can be merged to master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mutation returns relationship data like before the mutation took effect

3 participants