memgraph / mage

MAGE - Memgraph Advanced Graph Extensions :crystal_ball:
Apache License 2.0
259 stars 27 forks source link

Implement util.validatePredicate #525

Open katarinasupe opened 3 weeks ago

katarinasupe commented 3 weeks ago

On mutation, you get the following error:

"Function 'apoc.util.validatePredicate' doesn't exist."

To reproduce, run the attached code. Open Apollo server on localhost:4000. Run the following code to create user nodes:

# Create a user
mutation {
  createUsers(input: 
  [ { 
    name: "katarina"
  }]

  ) {
    users {
      id,
      name
    }
  }
}

# Create multiple users
mutation {
  createUsers(input: 
  [ { 
    name: "matea"
  },
  {
    name: "ante"
  },
  {
    name: "gabor"
  }]

  ) {
    users {
      id,
      name
    }
  }
}

Then, try the following mutation (connectOrCreate requires @unique decorator - we didn't document this well enough; it might have been added to never version):

# Create a post
mutation {
  createPosts(input: 
  [ { 
    content: "hello world!",
    creator: {
      connectOrCreate: {
        where: { node: { id: "06daddb7-1657-4e6a-8a7d-b11ec6d2698f" } }
        onCreate: { node: { name: "katarina" } }
      }
    }
  }]

  ) {
    posts {
      id,
      content
    }
  }
}

The above mutation results in the reported error, instead of creating a post.

This was reported on Discord.

antejavor commented 1 week ago

@katarinasupe Memgraph currently works on basic CRUD operations, it does not work in some specific cases where the apoc calls are needed.

The Neo4j graphQL changes the schema into the Cypher queries with hardcoded apoc calls.

The option is to code apoc modules into memgraph Mage modules that are missing and needed in the driver. Replace the apoc call with the Memgrpah Mage call QM call.

So, to be able to do this, we first need to code the following QM:

apoc.util.validate
apoc.util.validatePredicate

After that Memgraph needs to understand that it needs to change the query, as a first step I am transferring this issue to the Mage repository.

I think it is better to code the QMs and change the apoc calls as we move towards cipher generation from LLMs and convert from apoc to MAGE calls.

katarinasupe commented 1 week ago

So, @antejavor the above mentioned procedures need to be implemented and https://github.com/memgraph/mage/blob/bf4b04d10bc6750ba2b665399e48d893919c50d8/apoc_mappings.json updated to make GraphQL v5 work with Memgraph for basic CRUD operations if I understood correctly?

antejavor commented 2 days ago

@katarinasupe , as a first step, we can implement just util.validatePredicate in Mage, since it is not a void QM call, rather it returns the value. The util.validate is a void call, it is not clear how it should be replaced from the user's perspective and apoc.util.validate crashes Memgraph, as explained here. The linked issue is currently not blocker for GraphQL.