Comments (8)
From what I'm seeing, the remove mutation deletes the last record regardless of whether the ID exists or not.
from json-graphql-server.
I'm using version 2.1.3 from npm. If I start it with this data file:
module.exports = {
Orders: [
{
id: '12345',
status: 'DONE',
},
{
id: '12346',
status: 'BLOCKED',
},
{
id: '12347',
status: 'DONE',
},
],
};
then I run this mutation in GraphiQL:
mutation {
removeOrder(id: "12345")
}
I get this response:
{
"data": {
"removeOrder": null
}
}
Then I query for all orders again, and 12347 (the last one) is missing. 12345 (the one I told it to delete) is still there.
from json-graphql-server.
The id attributes in your data files must be integers @pjweisberg @robertbbb β
Unfortunately, if you create something using mutation (not initial data) and then attempt to remove it your response will be:
{
"data": {
"something": null
}
}
Interesting that only remove
is broken and not update
β it's a bug π
from json-graphql-server.
Interesting. Still a bug, but I guess that reduces the "how did anyone ever miss this?" factor. IDs still come out as strings in the query responses, which I why I didn't think of changing to integers.
In the real world IDs will frequently be UUIDs (or at least alphanumeric), but in my current project I can get away with assuming they're integers.
from json-graphql-server.
I completely agree. And so does Graphql:
The ID scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as "4") or integer (such as 4) input value will be accepted as an ID.
I was going through the code and found thisβ see comment in the remove resolver: https://github.com/marmelab/json-graphql-server/blob/master/src/resolver/Mutation/remove.js
So it seems the author is aware already. And it actually seems that the issue maybe on create.
from json-graphql-server.
And there's the "remove last element" but, too. Not found, so indexOfEntity is -1, and that's what happens when you pass -1 into Array.splice().
That, at least, is easy to fix.
from json-graphql-server.
PJ Weisberg's recent merge in fixed the problem of arbitrarily deleting the last item when no such item ID was found. There is still a problem with not being able to delete IDs specified as strings, but we found that a small change to src/resolver/Mutation/remove.js fixed that bug:
export default (entityData = []) => (_, { id }) => {
const parsedId = ${id}
; // surrounded by back-ticks that don't display on issues/66 properly.
const indexOfEntity = entityData.findIndex(e => ${e.id}
=== parsedId);
let removedEntity = undefined;
if (indexOfEntity !== -1) {
removedEntity = entityData.splice(indexOfEntity, 1)[0];
}
return removedEntity;
};
from json-graphql-server.
I still have this problem :( Removing existing or non-existing elements causes mentioned behavior and it is very problematic for me
from json-graphql-server.
Related Issues (20)
- Execution fails with error and return code 1 HOT 1
- Error while deleting: Boolean cannot represent a non boolean value HOT 2
- How to perform multiple create mutations in the same query?
- Deploy to Heroku fails with npm ERR! missing script: start HOT 1
- Fragments in nested JSON Array
- t is not a function HOT 8
- Create mutation does not require ID, but CreateMany mutation does HOT 1
- Treat date string as date type
- How to access in browser data after mutation? HOT 1
- node graphql connection refused/reset by peer in a docker container HOT 1
- [feature request] customize foreign key properties (*_id)
- write to db.js HOT 2
- Is not working, the next image is from my Terminal, there is a problem with QPortal ΒΏ? HOT 1
- Typescript support HOT 1
- Can this be used to mock Hasura GraphQL? HOT 1
- Support GraphQL v15 HOT 1
- Dynamic content? HOT 3
- Is there a way to save the mutations to the db.js file? HOT 2
- Cannot extend type "Workhsop" because it does not exist in the existing schema. HOT 2
- Move to apollo-server-express HOT 1
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 json-graphql-server.