Code Monkey home page Code Monkey logo

Comments (8)

Aurelsicoko avatar Aurelsicoko commented on July 19, 2024 1

@SachaG Thank for the clarification!

It would make more sense to keep the "top-level input argument" pattern for the input because it seems this pattern is recommended for payload as well.

Just like when you design your input, nesting is a virtue for your GraphQL payload. Always create a custom object type for each of your mutations and then add any output you want as a field of that custom object type. This will allow you to add multiple outputs over time and metadata fields like clientMutationId or userErrors.

from opencrud.

Aurelsicoko avatar Aurelsicoko commented on July 19, 2024

I think the last one is easier to use (from a front-end point of view) because you've only one argument to pass, and you don't need to pick the where condition from your object. In most cases, we're manipulating an entire user's object (in our states or reducers) and it's easier to send it directly into this input argument.

Moreover, when you're compatible with multiple DB with different identifiers (id, _id, ...), the last one is better again to handle it smoothly in the back-end. It's painless for front-end developers to use 👍

from opencrud.

SachaG avatar SachaG commented on July 19, 2024

Just to clarify, I think a better example would be:

  • multiple arguments:
updateUser(where: { id: "1" }, data: { name: "Karl" })
  • single argument:
updateUser(input: {where: { id: "1" }, data: { name: "Karl" }})

So the mutation still requires the same arguments, they're just nested inside a top-level input argument.

The idea being that if you then create a new version of your API with new arguments your mutation can then become (for example):

updateUser(input: {where: { id: "1" }, data: { name: "Karl" }}, input2: {query: { _id: "1" }, payload: { name: "Karl" }})

from opencrud.

SachaG avatar SachaG commented on July 19, 2024

For the payload I agree, but I was talking with @schickling and @sorenbs and we weren't sure if that pattern also made sense for the input.

from opencrud.

Aurelsicoko avatar Aurelsicoko commented on July 19, 2024

I tried to iterate with the example you gave me.

updateUser(input: { where: { id: "1" }, data: { name: "Karl" }}, input2: {query: { _id: "1" }, payload: { name: "Karl" }})

Without the top-level input argument, we could definitely do something like that and it does the same thing.

updateUser(where: { id: "1" }, data: { name: "Karl" }); // Old apps will use this query

updateUser(query: { _id: "1" },  data: { name: "Karl"}, payload: { name: "Karl" }); // New apps will use this query

I added a new argument payload, query to the top-level argument definition and _id for the query input definition. Since I've only added new things it doesn't break anything. Except that I can't rename/remove the top-level where argument and id from my current definition to not break the old apps.

I've certainly missed something in my thinking but it seems the only pain caused by the OpenCRUD specifications. You can't delete the top-level arguments but you can still rename them by adding new ones and use these new arguments instead of the old ones. I don't have any example in mind where I would need to rename the where and data arguments for a CRUD usage. It's pretty generic!

from opencrud.

SachaG avatar SachaG commented on July 19, 2024

I think I'm leaning towards not following that pattern. My mutations have at most 2 arguments anyway so I don't think it's worth adding that extra level of indirection all the time.

from opencrud.

ceefour avatar ceefour commented on July 19, 2024

strapi v3 is currently following Facebok/Apollo's recommendations with only one input & payload.

cc @Aurelsicoko

from opencrud.

ceefour avatar ceefour commented on July 19, 2024

There is an advantage of the "one input", for example MongoDB specifically distinguishes between update(One/Many) vs. replace(One/Many), and then we also have findOneAndUpdate() etc.

With OpenCRUD current draft:

mutation {
  updateManyUsers(where: {name_not: "Karl"}, data:{name: "Karl"}) {
    count
  }
}

Currently it doesn't seem to be possible to update individual fields (for example set viewCount=viewCount+1, or in MongoDB-speak {$inc: 'viewCount'}. Even if we add another mutation, the flexibility of single input is good here.

Also with update, we can't specify whether we want previous value or updated value, as MongoDB's findOneAndUpdate() allows. This requires another (optional) argument, and this could be put inside the single input instead of adding a third/etc. argument.

With updateManyUsers maybe client wants to know results not just count, and when dealing with multiple items then client will want to specify sorting, then this requires another argument in the mutation.

from opencrud.

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.