Neo4j GraphQL Server
  • Introduction
  • Neo4j GraphQL Server
  • Neo4j GraphQL Binding
    • neo4jGraphQLBinding
    • neo4jIDL
    • neo4jAssertConstraints
    • buildNeo4jTypeDefs
    • buildNeo4jResolvers
  • GRANDstack Starter
  • GraphQL Community Graph
Powered by GitBook
On this page
  • API Reference
  • Example
  • Resources
  1. Neo4j GraphQL Binding

neo4jAssertConstraints

Uses the APOC extension to keep Neo4j property constraints in sync with @unique fields.

Previousneo4jIDLNextbuildNeo4jTypeDefs

Last updated 6 years ago

In order to support the use of a @unique field directive, neo4jAssertConstraints can be used to send a Cypher query to your Neo4j instance that executes the apoc.schema.assert procedure. For each type with a @model directive, constraints are created and kept for any fields on that type with a @unique directive, in addition to all generated id fields.

API Reference

  • typeDefs (required): Your GraphQL type definitions in .

  • driver(required): Your Neo4j driver instance (More info ).

  • log (default: false): Logs result from operation.

Example

The following would result in the creation of an index and constraint on the name property of Technology nodes in your Neo4j instance.

import { neo4jAssertConstraints } from 'neo4j-graphql-binding';

const driver = neo4j.driver(
  process.env.NEO4J_URI || "bolt://localhost:7687",
  neo4j.auth.basic(
    process.env.NEO4J_USER || "neo4j",
    process.env.NEO4J_PASSWORD || "neo4j"
  )
);

const typeDefs = /* GraphQL */`
  type Technology @model {
    name: String! @unique
  }
`;

neo4jAssertConstraints({
  typeDefs: typeDefs,
  driver: driver,
  log: true
});

Resources

APOC: An Introduction to User-Defined Procedures and APOC

Neo4j Constraints

SDL format
here
https://neo4j.com/blog/intro-user-defined-procedures-apoc/
https://neo4j.com/docs/developer-manual/current/get-started/cypher/labels-constraints-and-indexes/