Comments (10)
Hi @vangavroche!
Did you try it? Mutations should handle both global (id
) and mongoose (_id
) ids.
from graffiti-mongoose.
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.
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.
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.
@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.
@vangavroche I've added the reference support too to the PR, although we might need more testing.
from graffiti-mongoose.
@tothandras thanks.
from graffiti-mongoose.
@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.
Yes, it works and solves the issue.
from graffiti-mongoose.
Released under v4.3.2
.
from graffiti-mongoose.
Related Issues (20)
- Implicit dependency on babel-polyfill HOT 9
- Cannot set currently-valued fields to null in update mutation HOT 2
- How to make a custom field: id? HOT 10
- "TypeError: Cannot read property 'forEach' of undefined" when embedded object field is a reference HOT 6
- Custom query thunk - accepts only InputObject types HOT 3
- Question on customQueries HOT 7
- Example project doesnt work with [email protected] and [email protected] HOT 1
- Async hook support HOT 2
- How to use Express Middleware for Authentication/Authorization. HOT 4
- Get specific field validation error?
- How to mutate nested Schema? HOT 3
- What is different between id and _id HOT 1
- UNMET PEER DEPENDENCY HOT 1
- Maintainer Volunteer Thread HOT 1
- Mongoose ObjectId and GraphQL id is not the same. How to link them? HOT 5
- It is possible to add some description to schema and to be reflected in the docs?
- Does graffiti-mongoose works with react-apollo ? HOT 2
- Custom mutations?
- Custom queries/mutations HOT 1
- setTypeFields bug
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 graffiti-mongoose.