neo4j-graphql / neo4j-graphql-js

NOTE: This project is no longer actively maintained. Please consider using the official Neo4j GraphQL Library (linked in README).
Other
608 stars 148 forks source link

Integers being converted to floats in Neo4j database #464

Closed asianfilm closed 3 years ago

asianfilm commented 4 years ago

Just wondering if this is a feature or a bug.

Given the schema:

type Edition {
  id: ID!
  year: Int!
}

When I run the following mutation, I get the expected integer response:

mutation {
  CreateEdition(
    year: 2021
  ) {
    year
  }
}

{
  "data": {
    "CreateEdition": {
      "year": 2021
    }
  }
}

But when I look at the database in Neo4j desktop, the year is being stored as 2021.0.

Other than the aesthetics of it, are there going to be any issues of Neo4j storing years from mutations as floats and years from APOC imports as integers? FYI, neo4j-graphql-js is correctly converting years (back) to integers in queries.

My Neo4j DB is at 3.5.19 and my neo4j-graphql-js is at 2.14.2. Running this on a Mac.

steezeburger commented 4 years ago

The only issue I've come across is when I'm trying to manually build a hash that represents the _Neo4jDateTimeInput input that can be used as a cypher param. I believe the library handles these javascript number values under the hood, but when you're implementing a custom mutation, you'll need to transform the datetime input first.

For instance, if you have a custom mutation:

createThing(
  start: _Neo4jDateTimeInput
): Thing

your custom mutation resolver would need to look like:

import { int } from 'neo4j-driver';

const createThing = async (object, params, context, info) => {
  let { start } = params;
  if (!start.formatted) {
    // map javascript Numbers to Neo4j ints
    start = Object.keys(start).map(key => int(start[key]));
  } else {
    start = start.formatted;
  }

  const session = context.driver.session();  
  const thing = await session.run(
    'CREATE (t:Thing { start: datetime($start) }) RETURN t', 
    { start },
  );
  return thing.properties;
};

That start variable can now be used as a param when querying against neo4j using cypher.

johnymontana commented 3 years ago

@asianfilm Thanks for reporting! This was indeed a bug and has been fixed in #513