pg_graphql icon indicating copy to clipboard operation
pg_graphql copied to clipboard

pg_graphql does not generate schema for array typed properties on mutation.

Open HadiSDev opened this issue 2 years ago • 5 comments

Describe the bug

Whenever I use the codegen to create the types from the queries it does not generate the properties with [Int] for the update type:

For example, the type "Profile" is correctly generated as:

type profiles {
    birthday: Date
    can_be_roommate: Boolean
    created_at: Datetime
    description: String
    display_name: String!
    employment: Int
    first_name: String!
    id: BigInt!
    last_name: String!
    search_as: Int
    tenant_attributes: [Int]
    user_id: UUID!
}

But its mutation type is missing the tenant_attributes

input profilesUpdateInput {
    birthday: Date
    can_be_roommate: Boolean
    created_at: Datetime
    description: String
    display_name: String
    employment: Int
    first_name: String
    last_name: String
    search_as: Int
    user_id: UUID
}

Error: × GraphQL Document Validation failed with 1 errors; Error 0: GraphQLDocumentError: Field "tenant_attributes" is not defined by type "profilesUpdateInput". Image

To Reproduce Steps to reproduce the behavior:

  1. Create a table with an array property. Eg. Int[]
  2. Add graphql plugin to table/db
  3. Get the schema via. the graphql endpoint
  4. Notice the update type

Expected behavior It should also include the array properties in the mutation types

Versions:

  • PostgreSQL: Supabase
  • pg_graphql: Whatever is on supabase

HadiSDev avatar Aug 27 '22 12:08 HadiSDev

Array types on mutations are not currently supported but it's something we're actively working towards. I'd expect it to land on the hosted platform in the next couple months

olirice avatar Aug 29 '22 14:08 olirice

Probably good idea to add this fact to the readme :)

HadiSDev avatar Aug 30 '22 04:08 HadiSDev

Is there another way to make an API call to update an array field on a table? Could we work around by using the REST endpoint? @olirice This is blocking me from moving forward.

birdwell avatar Sep 02 '22 03:09 birdwell

Yes, PostgREST does support updating an array column. You can achieve that with supabase-js if you're on the supabase platform or postgrest-js if not

olirice avatar Sep 02 '22 15:09 olirice

@olirice thank you for the suggestion, I'm looking at the documentation now.

birdwell avatar Sep 02 '22 16:09 birdwell