Skip to content

The order of the definition of an relation input has unexpected side effects #728

@megawubs

Description

@megawubs

Describe the bug
When I want to both sync existing relations and create a new relation on a BelongsToMany or MorphsToMany relationship, the order of the fields in the input type influences if the relation is actually stored or not. For example, if create comes before sync in the input type, the relation is created but sync is executed after the create, thus removing the relation with the newly created one. Once the sync key is moved before the create key, the sync happens before the create, thus making sure all relations are still set.

Expected behavior
When syncing and creating both in one mutation, the created entity should be linked, not only the synced. There should not be a dependancy on the order of the fields in the schema to get this to work.

Schema
This input does sync and store, but does not keep the relation of the stored tag

input UpdateTagRelation {
  create: [StoreTag!]
  connect: [Int!]
  sync: [Int!]
  disconnect: [Int!]
}

This input does sync and store, and keeps the relation of the stored tag.

input UpdateTagRelation {
  sync: [Int!]
  create: [StoreTag!]
  connect: [Int!]
  disconnect: [Int!]
}

Environment

Lighthouse Version: dev-master
Laravel Version: 5.8
PHP Version: 7.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error within Lighthouse

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions