Mutation using Relationship field allow use of more fields in { connect { id } }
See original GitHub issueFeature request
I takes multiple query to connect an existing item to Relationship item. First you have to query the item then send another query where you have to connect to this relationship item.
sometime you already have data which is not an ID, for example when you have forgotten password token, user coming to this url will have token but not id (assume id is different than token), then you have to call to get the id and then connect this to another item (assume we save token into a archived token list). this case you want to just use
mutation { createArchivedToken(data: { token: {connect: { token: $token } } }) {...fields} }
Describe the solution you’d like
I would like to use more field instead of just connect inside mutation. another example using a slug for post
mutation { updateUser(id: "some-id", data: {lastPost: {disconnectAll: true, connect: {slug: "post-slug }}}){id name lastPost { id author { id name } } } }
Describe alternatives you’ve considered
N/A
Additional context
this can enable more nested queries in future. Useful in case when you have some data already as part of other field but that is not a relationship field.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
I agree that we should restrict use of nested query to
WhereUnique
to keep it simple. there is also use case when you have Relationship set tomany: true
then this should also allow non unique connectioins.With the current structure of nested operations, we would have to limit it to
WhereUnique
fields I think, otherwise it could potentially return more than one item.