Comments (14)
Would be ideal if you can run an update without knowing the id in for the model, In my mind its kind of the point of an upsert really.
from prisma1.
We introduced a updateOrCreate
mutation (undocumented so far) that allows you to update a node by id or create a new one instead (if there is no node by that id), but after the initial feedback we got we are taking additional time to make it possible to update nodes by other unique fields. We're not on a specific timeline for this feature though.
A current workaround is first querying the node in question and then either using the update if it exists or the create mutation.
from prisma1.
It would also be great if upserts were available within nested mutations.
For example, assuming the following schema (not showing id/created/updated fields):
type Book {
isbn: String! @isUnique
title: String!
reviews: [Review!]! @relation(name: "BookReviews")
}
type Review {
title: String!
book: Book @relation(name: "BookReviews")
}
Let's say I wanted to add a new Review
, but don't know if the relevant Book
already exists in my data or not. I'd like to be able to use a createReview
mutation that allows me to include the book
field's isbn
and title
(similar to how nested create mutations currently work). That way, a new Book
could be created if necessary, otherwise it would just relate the existing Book
(with a matching isbn
) to my newly created Review
.
from prisma1.
@marktani Any plans to add support to Graphcool? I would really love to use updateOrCreate
without knowing the ID
first.
from prisma1.
No, Prisma is being developed separately from Graphcool Framework. You can read more about Prisma and Graphcool Framework in the Forum.
from prisma1.
This has been implemented in the Prisma 1.0 release.
from prisma1.
When can we expect to use this feature? What are workarounds for the time being?
from prisma1.
Thanks for the quick response as always @marktani! So updateOrCreate
let's you specify the id for creation? For example, my use case involves the login/signup flow:
- User goes through auth0 login popup
- On authentication set the token in localStorage, getUserInfo from auth0 and create user
- If creation fails with error code
3023
(user exists), updateUser - After creation or update, reload page to add authorization header with token from localStorage to
networkInterface
At this point I can query query { user { id } }
and get the id, but not when I'd like to perform the user update in step 3. If updateOrCreate
will allow me to create a user node with the id supplied from auth0, then I can use that id in the authorization callback to update the node on future logins. Alternatively, if I could update the user node by specifying the unique auth0UserId
field that could also solve my problem.
from prisma1.
Still doesn't look like it has made it into the Docs. Am I safe to use the undocumented version? Is this still on the horizon? I see this issue was part of the GitHub project tracker that was closed May 3rd. Has the project roadmap moved?
from prisma1.
Hey @mjsisley just saw this. updateOrCreate
is still undocumented and may receive breaking changes in the future, when we add more functionality to it.
@mvanlonden It sounds like your workflow is nicely covered by the custom authentication feature currently in beta, here's an example: https://github.com/graphcool-examples/functions/tree/master/auth0-authentication
from prisma1.
@export-mike +1
from prisma1.
Assuming this means it's usable outside of Prisma also? Just using the graphcool cloud?
from prisma1.
I am wondering if @shanecav case is possible now?
I can see in prisma there's field create
and connect
. inside nested mutation. Thus in @shanecav case. would be nice if we have something like createOrConnect
?
from prisma1.
Thanks a lot for bringing this up @muhajirframe. There's a now a new feature request for adding createOrConnect
support: #3724
from prisma1.
Related Issues (20)
- Self-relation column order? HOT 1
- Prisma1 with Apple M1 HOT 7
- Mutations with disconnect=true on an relation that is not connected to anything fails with an error HOT 1
- Circular dependency while mocking the Prisma client using both approach singelton and context
- host.docker.internal not working on prismagraphql/prisma:1.34 on docker-compose (1.29.2) docker 20.10.9 CentOS 8.4.2105 HOT 1
- Intermittent P1001 - "Can't reach database server..." HOT 1
- `updatedAt` field not changing after running a connect operation via the update mutation HOT 1
- Prisma 1.34 documentation errors HOT 1
- Invalid Issue Documentation link HOT 1
- log4j - CVE-2021-4428 HOT 2
- The type of `where` part of `delete` function is wrong when using `@@unique`
- Prisma 1 Cloud was sunset on September 1st, 2022 HOT 3
- Error prisma1 deploy HOT 1
- Cascade delete not set on one-to-many relation HOT 1
- prisma1 introspect does not return anything
- updatedFields always returns an empty array HOT 1
- Prisma1 deploy throws 504 Gateway Time-out randomly HOT 2
- "Join" where result would have been a big data set throws an error (performance) HOT 1
- Issues adding or modifying records in Admin
- Prisma 1 was deprecated on Sept, 1st 2022 — Upgrade to the latest version of Prisma
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prisma1.