Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Neo4jError: Property values can only be of primitive types or arrays thereof #23

Closed
gooftroop opened this issue Sep 21, 2018 · 6 comments

Comments

@gooftroop
Copy link

Ran into the error 'Neo4jError: Property values can only be of primitive types or arrays thereof' while attempting to create a node with a point.
The property shape is:

{
  createdAt: <default value of new Date().toISOString()>,
  location: {
    latitude: <float>,
    longitude: <float>,
  },
  userId: 1,
}

The code being ran is:

const result = await neo4j.model(CHECKIN).create({ ...args.data });

The query being executed is:

"CREATE
(this:Checkin { createdAt: $this_createdAt, id: $this_id, location: $this_location, userId: $this_userId })

RETURN

     this { 
        .*
        ,__EAGER_ID__: id(this)
        ,__EAGER_LABELS__: labels(this)
    }"

The param object is:
params

I'm still trying to debug, but I'm hoping you've encountered this issue before?

@adam-cowley
Copy link
Owner

adam-cowley commented Sep 21, 2018

I'm assuming this is down to the date not being converted to the native Neo4j type. For argument sake can you try passing through a neo4j date while I work on a fix?

console.log(createdAt.toString()) // 2018-01-02T12:34:56.1234Z
const nativeDate = new neo4j.temporal.DateTime( createdAt.toString() ) ) 

https://www.adamcowley.co.uk/neo4j/neo4j-temporal-dates-javascript/

@gooftroop
Copy link
Author

I think this will have the same issue as I noted in issue #22? The Joi validation will only allow strings to pass the datetime type

@gooftroop
Copy link
Author

gooftroop commented Sep 21, 2018

I'm able to create temporal DateTime using the following snippet from my schema:

createdAt: {
    default: () => new neo4j.types.DateTime.fromStandardDate(new Date()),
    required: true,
    type: 'datetime',
  },

However, this does fail the Joi validation for datetime since the value being validated is an Object rather than a string. Updating the default function to the following allows it to pass validation, but I still get the same error I initially reported:

createdAt: {
    default: () => new neo4j.types.DateTime.fromStandardDate(new Date()).toString(),
    required: true,
    type: 'datetime',
  },

As a note, I'm using neo4j-driver@1.7

@adam-cowley
Copy link
Owner

I'll spend some time on handling each of the temporal and spatial types over the next couple of days. Bear with me

@gooftroop
Copy link
Author

Sounds good 👍
Let me know if I can assist in anyway

@gooftroop
Copy link
Author

verified fixed. nice! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants