cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

GraphQL id=null yet Neo4J <id> exists

When mutating using graphql playground id=null is returned, yet the Neo4j browser shows a value for "id". What am I missing here?

8 REPLIES 8

William_Lyon
Graph Fellow

Hi @r.chevalier335 - what does your GraphQL typedef look like for the type in question? And the GraphQL query?

Are you referring to the Neo4j internal node id, or a property named id that you are setting the value of explicitly? Neo4j internal node ids are exposed in the GraphQL integration as field _id and show up in Neo4j browser as <id>.

Thanks for responding Will.

No, I didn't explicitly set an id value. I was expecting the Neo4j id to be returned. I've done a bit of reading and understand that the Neo4j id might not be reliable, and it's better to explicitly make my own. Is that true?

Yes, Neo4j internal ids should not be used in external systems as the internal ids can be reclaimed and reused later on.

So in general yes better to create a UUID or something and set it explicitly. If you're using neo4j-graphql.js a UUID will be generated and set automatically for any ID! field if not specified in the create mutation.

You can also use apoc.create.uuid to generate a UUID when creating nodes.

Hello William -

If you're using neo4j-graphql.js a UUID will be generated and set automatically for any ID! field if not specified in the create mutation.

I noticed this behavior when creating new nodes. However, I noticed this is not happening in the case of creating new relationships. I am using the community edition, and thought to add an ID! to the relationship type. In this case, it seems I am expected to provide the ID myself. I guess I am also wondering if I ever need to select a relationship by ID rather than simply match to its nodes.

My schema looks something like this.

# For company and product, Id's are generated automatically when not provided at creation time.
type Company {
  companyId: ID! 
  name: String!
  makes: [Makes]
}
type Product {
  productId: ID! 
  name: String!
  madeBy: [Makes]
}

# Here, ID is required (in addition to from and to)
type Makes @relation(name: "MAKES") {
  makesId: ID!
  from: Company
  to: Product
  source: String!
}

I call it like so

mutation AddCompanyMakes($companyId: ID!, $productId: ID!) {
  AddCompanyMakes(
    from: { companyId: $companyId }
    to: { productId: $productId }
    data: { source: "test" } # makesId REQUIRED HERE
  ) {
    from {
      companyId
    }
    to {
      productId
    }
    source
  }
}

Awesome. This is very helpful. Thanks William.

I've had partial success. Still unable to delete and update. Any help is appreciated.

Here is my schema:
type Thing {
_id: ID!
name: String
}

type Query {
things: [Thing]!
thing(_id: ID!): Thing
}

type Mutation {
createThing(name: String): Thing
updateThing(_id: ID!, name: String!): Thing
deleteThing(_id: ID!): Thing
}

Here are my queries/mutations and results:


ALL THINGS - Works


query{things{
_id
name
}
}
RETURNS:
{
"data": {
"things": [
{
"_id": "4",
"name": "Thing 1"
},
{
"_id": "67",
"name": "Thing 2"
},
{
"_id": "68",
"name": "Thing 3"
},
{
"_id": "69",
"name": "Thing 3"
},
{
"_id": "70",
"name": "Thing 3"
},


ONE THING - Works


query{thing(_id:"4"){
_id
name
}
}
RETURNS:
{
"data": {
"thing": {
"_id": "4",
"name": "Thing 1"
}
}
}


CREATE A THING - Works


mutation{createThing(
name: "Thing 99993"
)
{
_id
name
}
}
RETURNS:
{
"data": {
"createThing": {
"_id": "77",
"name": "Thing 99993"
}
}
}


UPDATE A THING - Nope


mutation{updateThing(
_id: "4"
name: "Update Node 1"
){
_id
name
}
}
RETURNS:
{
"data": {
"updateThing": null
}
}


DELETE A THING - Nope It says the parameter is missing but I provided it.???


mutation {deleteThing(_id: "4"){
_id
name
}
}
RETURNS:
{
"errors": [
{
"message": "Expected parameter(s): _id",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"deleteThing"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"code": "Neo.ClientError.Statement.ParameterMissing",
"name": "Neo4jError",
"stacktrace": [
"Neo4jError: Expected parameter(s): _id",
"",
" at captureStacktrace (/home/rchevalier/dev/grand-stack/api/node_modules/neo4j-driver/lib/v1/result.js:199:15)",
" at new Result (/home/rchevalier/dev/grand-stack/api/node_modules/neo4j-driver/lib/v1/result.js:65:19)",
" at _newRunResult (/home/rchevalier/dev/grand-stack/api/node_modules/neo4j-driver/lib/v1/transaction.js:354:10)",
" at Object.run (/home/rchevalier/dev/grand-stack/api/node_modules/neo4j-driver/lib/v1/transaction.js:238:14)",
" at Transaction.run (/home/rchevalier/dev/grand-stack/api/node_modules/neo4j-driver/lib/v1/transaction.js:104:26)",
" at /home/rchevalier/dev/grand-stack/api/node_modules/neo4j-graphql-js/dist/index.js:91:25",
" at TransactionExecutor._safeExecuteTransactionWork (/home/rchevalier/dev/grand-stack/api/node_modules/neo4j-driver/lib/v1/internal/transaction-executor.js:134:22)",
" at TransactionExecutor._executeTransactionInsidePromise (/home/rchevalier/dev/grand-stack/api/node_modules/neo4j-driver/lib/v1/internal/transaction-executor.js:122:32)",
" at /home/rchevalier/dev/grand-stack/api/node_modules/neo4j-driver/lib/v1/internal/transaction-executor.js:61:15",
" at new Promise ()"
]
}
}
}
],
"data": {
"deleteThing": null
}
}

I posted a question and then immediately realized my error.

How is it supposed to work when you want to set the id using apoc.create.uuid using a mutation?

I am getting the following type of error message in my GRANDstack app:
2X_a_a851e81a5b22ff0626cf212cf027a0f2d673835c.png

Should I use the apoc.create.uuid or should I set id?