Graphql-engine: support for postgresql ARRAYS []

Created on 6 Dec 2018  路  4Comments  路  Source: hasura/graphql-engine

Given this SQL schema:

CREATE TABLE public."table" (
    "textArray" text[]
)

Graphql engine returns an error when trying to mutate:

{ 
  name: 'FormatedError',
  message: 'Unknown error',
  originalError: 
    { 
       path: '$.variableValues[0].textArray',
       error: 'A string is expected for type : _text',
       code: 'parse-failed'
     }
}

Is there a workaround? Many thanks

server question

Most helpful comment

@sulliwane You can pass the array value as text since all postgres types which are not natively supported by GraphQL Engine are treated as text.

This mutation will go through:

mutation {
  insert_table(objects:{
    textArray: "{hello, world}"
  }) {
    returning {
      textArray
    }
  }
}

with response:

{
  "data": {
    "insert_table": {
      "returning": [
        {
          "textArray": [
            "hello",
            "world"
          ]
        }
      ]
    }
  }
}

All 4 comments

@sulliwane You can pass the array value as text since all postgres types which are not natively supported by GraphQL Engine are treated as text.

This mutation will go through:

mutation {
  insert_table(objects:{
    textArray: "{hello, world}"
  }) {
    returning {
      textArray
    }
  }
}

with response:

{
  "data": {
    "insert_table": {
      "returning": [
        {
          "textArray": [
            "hello",
            "world"
          ]
        }
      ]
    }
  }
}

thanks a lot, it works perfectly!

About the curly brackets {} for the array, may I ask what kind of "standard" is that (obviously not JSON format) is it related to graphql or postgres or hasura?

{} is how arrays are represented in Postgres [1]

[1] https://www.postgresql.org/docs/9.1/arrays.html

Ok, got it. closing then, thanks a lot @shahidhk

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jjangga0214 picture jjangga0214  路  3Comments

anisjonischkeit picture anisjonischkeit  路  3Comments

shahidhk picture shahidhk  路  3Comments

cpursley picture cpursley  路  3Comments

lishine picture lishine  路  3Comments