Giter Site home page Giter Site logo

Upsert Mutations about prisma1 HOT 14 CLOSED

prisma avatar prisma commented on April 30, 2024 26
Upsert Mutations

from prisma1.

Comments (14)

export-mike avatar export-mike commented on April 30, 2024 25

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.

marktani avatar marktani commented on April 30, 2024 13

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.

shanecav avatar shanecav commented on April 30, 2024 12

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.

pugson avatar pugson commented on April 30, 2024 12

@marktani Any plans to add support to Graphcool? I would really love to use updateOrCreate without knowing the ID first.

from prisma1.

marktani avatar marktani commented on April 30, 2024 7

No, Prisma is being developed separately from Graphcool Framework. You can read more about Prisma and Graphcool Framework in the Forum.

from prisma1.

marktani avatar marktani commented on April 30, 2024 6

This has been implemented in the Prisma 1.0 release.

from prisma1.

mvanlonden avatar mvanlonden commented on April 30, 2024

When can we expect to use this feature? What are workarounds for the time being?

from prisma1.

mvanlonden avatar mvanlonden commented on April 30, 2024

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:

  1. User goes through auth0 login popup
  2. On authentication set the token in localStorage, getUserInfo from auth0 and create user
  3. If creation fails with error code 3023 (user exists), updateUser
  4. 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.

mjsisley avatar mjsisley commented on April 30, 2024

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.

marktani avatar marktani commented on April 30, 2024

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.

sabuydee avatar sabuydee commented on April 30, 2024

@export-mike +1

from prisma1.

tehwayne avatar tehwayne commented on April 30, 2024

Assuming this means it's usable outside of Prisma also? Just using the graphcool cloud?

from prisma1.

muhajirdev avatar muhajirdev commented on April 30, 2024

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.

schickling avatar schickling commented on April 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.