Error: _id.map is not a function
Hey, I'm getting this error when trying simple pagination from GrapihQL. I also posted this on #90 but since it's closed - I think no one would look at it now. I'm on grafitti-mongoose 5.0.10 and as far as I can tell this is not resolved by #100.
The mongoose schema I am using (reduced for brevity):
var itemSchema = Schema({
title: String,
description: String,
slug: String,
tags: String,
updatedAt: { type: Date, default: Date.now },
relatedItems: [{ type: Schema.Types.ObjectId, ref: 'Item' }]
});
And the query resulting in the error:
{
items(id: "570a6a89d675be1c3006dac8") {
_id
relatedItems(first: 2, after: "Y29ubmVjdGlvbi41NzBhNmE4OWQ2NzViZTFjMzAwNmRhY2E=") {
edges {
cursor
node {
_id
}
}
}
}
}
Let me know if I can provide any more information on this problem.
"graphql": "^0.5.0",
"mongoose": "^4.4.12"
"@risingstack/graffiti": "^3.0.3",
"@risingstack/graffiti-mongoose": "^5.0.10",
Works for me. Do you have all items in the other table (required to complete the query)?
I also have this error when trying to implement pagination. I have a connection which I am trying to load more results. There are 22 nodes in my edge and if i query 6, then onclick request +6 more I get the error. With initial variables at 25 or any number there is no issue, only when updating relay variables. Anyone see what I could be doing wrong?
Inside the header this is the error
{statusCode: 400, error: "Bad Request", message: "_id.map is not a function"}
The component
class CardImageList extends React.Component {
render() {
var currentNumber = this.props.relay.variables.limit;
var buttonStyle = {};
if (!this.props.content.pages.pageInfo.hasNextPage) {
buttonStyle.display = 'none';
}
return (
<div>
<Grid>
{this.props.content.pages.edges.map((edge, index, arr) =>
<Cell>
<CardImageListItem page={edge.node} />
</Cell>
)}
</Grid>
<div>
<button
style={buttonStyle}
onClick={() => this.props.relay.setVariables({limit: currentNumber + 6})}>
load more
</button>
</div>
</div>
);
}
};
export default Relay.createContainer(Radium(CardImageList), {
initialVariables: {
limit: 6
},
fragments: {
content: () => Relay.QL`
fragment on Content {
pages(first: $limit) {
edges {
cursor
node {
${CardImageListItem.getFragment('page')}
}
},
pageInfo {
startCursor
endCursor
hasPreviousPage
hasNextPage
}
}
}
`,
}
});
Versions:
"graphql": "^0.5.0",
"graphql-relay": "^0.4.1",
"react-relay": "^0.8.1",
"@risingstack/graffiti": "^3.0.4",
"@risingstack/graffiti-mongoose": "^5.1.0",
"mongoose": "^4.4.17",
(on windows 10)
Anymore info needed let me know.