简体   繁体   English

UUID类型的列的Graphql突变

[英]Graphql mutation for a column of type UUID[]

I'm using a postgraphql autogenerated mutation to create a row with graphql in a in a postgres table that has a column of datatype UUID[]. 我正在使用postgraphql自动生成的突变在具有数据类型UUID []列的postgres表中的graphql中创建一行。

However, there doesn't seem to be a way to save this UUID[] data with graphql? 但是,似乎没有办法用graphql保存此UUID []数据吗? Is this a datatype that graphql doesn't account for or am I wrongly forming the array? 这是graphql无法说明的数据类型,还是我错误地形成了数组?

When I go to create the row in graphiql: 当我在graphiql中创建行时:

mutation {
  createJob(
    input: {
      user_ids: ["5b7323ac-e235-4edb-bbf9-97495d9a42a1"], 
      instructions: "Job Instructions", 
      publishedDate: "2017-06-07"}
   }
 )
}

I get the following error: 我收到以下错误:

"message": "column \"user_ids\" is of type uuid[] but expression is of type text[]"

Is a UUID technically not stored like text? 从技术上讲,UUID是否不像文本一样存储? I've tried different ways of forming the the UUID array but nothing seems to work 我尝试了各种方法来形成UUID数组,但似乎没有任何效果

You can probably have a workaround to this problem by creating an implicit cast : 也许可以有一个解决此问题的创建隐式转换

CREATE CAST (text[] AS uuid[])
    WITH INOUT
    AS IMPLICIT ;

PostgreSQL will automatically do the conversion from text[] to uuid[] ; PostgreSQL将自动执行从text[]uuid[]的转换; which just seems that is the needed step. 这似乎是必需的步骤。


NOTE: The above code must be executed from "the owner of type uuid[] or text[]", which usually means: postgres or the database owner. 注意:上面的代码必须从“ uuid []或text []类型的所有者”执行,通常表示: postgres或数据库所有者。


To check that it works, you may just do: 要检查其是否有效,您可以执行以下操作:

CREATE TABLE t
(
   ids uuid[]
) ;

INSERT INTO t 
    (ids)
VALUES
    (ARRAY['5b7323ac-e235-4edb-bbf9-97495d9a42a1','5b7323ac-e235-4edb-bbf9-97495d9a42a2']),
    (ARRAY['6b7323ac-e235-4edb-bbf9-97495d9a42a1']) ;

... and then, test it with GraphQL ...然后使用GraphQL测试

This was a bug in PostGraphQL; 这是PostGraphQL中的错误; it's been fixed in version 4 (which has not been released yet, but you can install via npm install postgraphql@next ) 它已在版本4中得到修复(尚未发布,但是您可以通过npm install postgraphql@next

More information: https://github.com/postgraphql/postgraphql/issues/516 更多信息: https : //github.com/postgraphql/postgraphql/issues/516

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 varchar[ ] 列类型转换为 uuid[ ] - convert varchar[ ] column type to uuid[ ] 使用Graphql突变更新Postgres表中的列值 - Update a column value in a Postgres table using Graphql mutation postgreSQL中的UUID应该是什么列类型? - What column type should UUID be in postgreSQL? Postgresql 将列类型从 int 更改为 UUID - Postgresql change column type from int to UUID EF Core - 在 PostgreSQL 中将列类型从 varchar 更改为 uuid 13:列无法自动转换为类型 uuid - EF Core - Change column type from varchar to uuid in PostgreSQL 13: column cannot be cast automatically to type uuid 使用 CASE 表达式更新列抛出错误:列“external_uuid”的类型为 uuid,但表达式的类型为 boolean - Updating a column by using CASE expression throwing ERROR: column "external_uuid" is of type uuid but expression is of type boolean 休眠 UUID 作为 UUID 类型 - Hibernate UUID as UUID type JOOQ-列“ id”的类型为uuid,但表达式的类型为字符变化 - JOOQ - column “id” is of type uuid but expression is of type character varying 错误:列“id”是 uuid 类型,但表达式是 bytea 类型 - ERROR: column "id" is of type uuid but expression is of type bytea PostgreSQL - 错误:列“id”是 uuid 类型,但表达式是整数类型 - PostgreSQL - ERROR: column “id” is of type uuid but expression is of type integer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM