Git Product home page Git Product logo

Comments (8)

pjweisberg avatar pjweisberg commented on May 22, 2024

From what I'm seeing, the remove mutation deletes the last record regardless of whether the ID exists or not.

from json-graphql-server.

pjweisberg avatar pjweisberg commented on May 22, 2024

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.

svey avatar svey commented on May 22, 2024

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.

pjweisberg avatar pjweisberg commented on May 22, 2024

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.

svey avatar svey commented on May 22, 2024

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.

pjweisberg avatar pjweisberg commented on May 22, 2024

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.

a-rcrawford avatar a-rcrawford commented on May 22, 2024

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.

DarkEye123 avatar DarkEye123 commented on May 22, 2024

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)

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.