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

Conversation

@rakeshkky
Copy link
Member

@rakeshkky rakeshkky commented Oct 22, 2019

Description

If a table has a column with the array type then insert mutation to that table with returning its relationships throws an unexpected error.
As given in #3148:
For the following mutation:

mutation MyMutation {
  insert_site(objects: {name: "My Site"}, on_conflict: {constraint: site_name_key, update_columns: name}) {
    returning {
      id
      name
      site_trials {
        id
      }
    }
  }
}

Gives the following unexpected error:

{
  "errors": [
    {
      "extensions": {
        "path": "$.selectionSet.insert_site.args.objects",
        "code": "parse-failed"
      },
      "message": "A string is expected for type : _text"
    }
  ]
}

When relationship fields are found in returning fields, the server performs the mutation in two steps:

  1. Mutate with returning all columns
  2. Parse the returned column rows and query the returning fields.

Refer to commits 5f274b5 and 5bafdce to learn more about the above steps.

In step 2, parsing the array column values fails since our parser expects String representation of Postgres arrays. There are two ways to solve this problem

  1. The PR native support for postgres array types (close #348) #2243 auto-fixes the problem since it has support for arrays. But seems like it is not going out any soon.
  2. Perform the insert with returning the Postgres column values as Strings (except for geojson). It is kind of a hack and implemented in this PR.

Affected components

  • Server
  • Tests

Related Issues

Fix #3148 & #2520

Solution and Design

As mentioned in the above description, the mutated column values are returned as text.

Steps to test and verify

Follow the reproduction guide given in #3148 or #2520 and error shouldn't happen.

Limitations, known bugs & workarounds

@rakeshkky rakeshkky changed the title fix insert with nested returning clause fails alongside text[] column (fix #3148) fix insert with nested returning clause fails alongside text[] column (fix #3148 & #2580) Oct 22, 2019
@netlify
Copy link

netlify bot commented Oct 22, 2019

Deploy preview for hasura-docs ready!

Built with commit a21d504

https://deploy-preview-3198--hasura-docs.netlify.com

@hasura-bot
Copy link
Contributor

Review app for commit 977969d deployed to Heroku: https://hge-ci-pull-3198.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3198-977969dc

@rakeshkky rakeshkky changed the title fix insert with nested returning clause fails alongside text[] column (fix #3148 & #2580) fix insert with nested returning clause fails alongside text[] column (fix #3148 & #2520) Oct 23, 2019
@rakeshkky rakeshkky self-assigned this Nov 4, 2019
@rakeshkky rakeshkky force-pushed the issue-3148-mutation-returning branch 2 times, most recently from b0df70d to ad8b807 Compare November 5, 2019 06:30
@hasura-bot
Copy link
Contributor

Review app for commit ad8b807 deployed to Heroku: https://hge-ci-pull-3198.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3198-ad8b8076

@rakeshkky rakeshkky marked this pull request as ready for review November 5, 2019 13:01
@rakeshkky rakeshkky added the c/server Related to server label Nov 5, 2019
@hasura-bot
Copy link
Contributor

Review app for commit 7896326 deployed to Heroku: https://hge-ci-pull-3198.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3198-78963269

Copy link
Contributor

@lexi-lambda lexi-lambda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM apart from two tiny comments.

@rakeshkky rakeshkky requested a review from lexi-lambda November 6, 2019 10:00
@hasura-bot
Copy link
Contributor

Review app for commit 6c9633c deployed to Heroku: https://hge-ci-pull-3198.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3198-6c9633c8

@hasura-bot
Copy link
Contributor

Review app for commit b423249 deployed to Heroku: https://hge-ci-pull-3198.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3198-b4232494

@hasura-bot
Copy link
Contributor

Review app for commit a21d504 deployed to Heroku: https://hge-ci-pull-3198.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3198-a21d5042

@lexi-lambda lexi-lambda merged commit 37dd096 into hasura:master Nov 7, 2019
@hasura-bot
Copy link
Contributor

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

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

Labels

c/server Related to server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Insert with nested returning clause fails alongside text[] column

3 participants