Coder Social home page Coder Social logo

Comments (10)

tothandras avatar tothandras commented on July 19, 2024

Hi @vangavroche!
Did you try it? Mutations should handle both global (id) and mongoose (_id) ids.

from graffiti-mongoose.

vangavroche avatar vangavroche commented on July 19, 2024

In the example https://github.com/RisingStack/graffiti-mongoose/blob/master/example/user.js where User has friends that are also "User"s

After I created two users (without any friends), the query responses of "users {id, name}" are like

{
  "data": {
    "users": [
      {
        "id": "VXNlcjo1NjY1YWZkMGU1ZWQwMTAzMWU5ODc3MjQ=",
        "name": "Kaka"
      },
      {
        "id": "VXNlcjo1NjY2NWI0M2U1ZWQwMTAzMWU5ODc3MjY=",
        "name": "Messi"
      }
    ]
  }
}

The generated mutation to add user has input that contains

name: String
age: Float
createdAt: Date
friends: [ID]
clientMutationId: String!

When I try to add a user using mutation

mutation M {
  addUser(input: {name:"Ronaldo", age: 12, friends:["VXNlcjo1NjY2NWI0M2U1ZWQwMTAzMWU5ODc3MjY="], clientMutationId:"1234"}) {
    changedUserEdge {
      node {
        name
      }
    }
  }
}

It won't work, since the ID is not a valid one.

from graffiti-mongoose.

vangavroche avatar vangavroche commented on July 19, 2024

Do you mean when I query the ID to set such association ("friends" in this case), I should explicitly get the _id to use?

Using query like this:

query U {
  users {
    _id, name
  }
}

from graffiti-mongoose.

vangavroche avatar vangavroche commented on July 19, 2024

BTW, is there any special reason why the singular object reference is not supported in the mutation field generation?

https://github.com/RisingStack/graffiti-mongoose/blob/master/src/schema/schema.js#L124

In the case like

//
const TodoSchema = new mongoose.Schema({
  text: {
    type: String
  },
  createdAt: {
    type: Date,
    default: Date.now()
  },
  completed: {
    type: Boolean,
    default: false
  },
  owner: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User'
  }
});

owner field is not used as the mutation input.

To me it seems an easy problem to solve

else {
        // In this case it is assume that the field is a singular object reference like
        // {
        //    type: ObjectId,
        //    ref: "User"
        // }
        //
        inputFields[field.name] = {
          name: field.name,
          type: _graphql.GraphQLID
        };
      }

But I wonder if there's anything I'm missing.

from graffiti-mongoose.

tothandras avatar tothandras commented on July 19, 2024

@vangavroche Okay, the add mutation error is a real bug, see #71 for a quick fix.
I am looking into the object input now.

from graffiti-mongoose.

tothandras avatar tothandras commented on July 19, 2024

@vangavroche I've added the reference support too to the PR, although we might need more testing.

from graffiti-mongoose.

vangavroche avatar vangavroche commented on July 19, 2024

@tothandras thanks.

from graffiti-mongoose.

tothandras avatar tothandras commented on July 19, 2024

@vangavroche Can you verify that it resolves your issues? :) I could have missed something. Please add a thumbs up to the PR, I will merge it then.

from graffiti-mongoose.

vangavroche avatar vangavroche commented on July 19, 2024

Yes, it works and solves the issue.

from graffiti-mongoose.

tothandras avatar tothandras commented on July 19, 2024

Released under v4.3.2.

from graffiti-mongoose.

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.