Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Enable nested relationships in mutation inputs

Aperta
#294 21 commenti 32 reazioni 1 assegnatario Vedi su GitHub

@olirice ci sta già lavorando.

Dal 20/12/2022.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

enhancement

Describe the bug
It's not possible to insert an object along with its related object(s) in a single mutation. But that's exactly the beauty of GraphQL!

To Reproduce
Consider the following simple extract of a schema (Query, update, delete and all other types omitted for simplicity), where basically we have a One-To-Many relationship between Post and PostImage tables:


type Post {
  id: UUID!
  content: String!
  createdAt: Datetime!
  postImageCollection(
    first: Int
    last: Int
    before: Cursor
    after: Cursor
    filter:PostImageFilter
    orderBy: [PostImageOrderBy!]
  ): PostImageConnection
}

type PostImage {
  id: UUID!
  postId: UUID!
  imageUrl: String!
  createdAt: Datetime!
  post: Post
}

type PostImageConnection {
  edges: [PostImageEdge!]!
  pageInfo: PageInfo!
}

type PostImageEdge {
  cursor: String!
  node: PostImage!
}

input PostInsertInput {
  id: UUID
  content: String!
  createdAt: Datetime
}

type PostInsertResponse {
  affectedCount: Int!
  records: [Post!]!
}

input PostImageInsertInput {
  id: UUID
  imageUrl: String!
  postId: UUID!
  createdAt: Datetime
}

type PostImageInsertResponse {
  affectedCount: Int!
  records: [PostImage!]!
}

type Mutation {

  insertIntoPostCollection(objects: [PostInsertInput!]!): PostInsertResponse

  insertIntoPostImageCollection(objects: [PostImageInsertInput!]!): PostImageInsertResponse

}

Since I usually create a PostImage row every time I create a Post row, I need to execute two separate mutations to achieve this.
First:

mutation CreatePost {
  insertIntoPostCollection(objects: {...}) {
    affectedCount
    records {
      id
    }
  }
}

And after getting the result from CreatePost, I can execute:

mutation CreatePostImage {
  insertIntoPostImageCollection(objects: {
    imageUrl: "whatever",
    postId: "" # here goes the Post id from previous mutation result
  }) {
    affectedCount
    records {
      id
    }
  }
}

Expected behavior
Expose nested objects in mutation inputs, so that I can directly create a Post along with a PostImage with just one mutation:

mutation CreatePost {
  insertIntoPostCollection(objects: {
     content: "blabla",
     postImageCollection: {
       objects: {
         imageUrl: "whatever"
       }
     }
  }) {
    affectedCount
    records {
      id
      content
      postImageCollection(...) {
        imageUrl
        postId # this is automatically assigned by the mutation itself
      }
    }
}

See Hasura docs on this topic for reference.

Versions:

  • PostgreSQL: any (this issue does not relate to Postgres itself)
  • pg_graphql commit ref: b1cc167
Lingua principale
Rust
Stelle
3.4k
Fork
143
Merge medio
4h 47m
PR unite (30g)
2

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di supabase/pg_graphql

Tutte le issue di supabase/pg_graphql

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.