neode icon indicating copy to clipboard operation
neode copied to clipboard

Error when indexed is set to true: Not sure how to validate indexed on name

Open brvnonascimento opened this issue 3 years ago • 6 comments

I'm setting my schema as typed in the Schema Object type definition:

const UserSchema =  {
  name: {
    type: 'string',
    indexed: true,
    required: true
  },
  email: {
    type: 'string',
    indexed: true,
    unique: true,
    required: true
  }
}

When I setup my server with shema.install() all the indexes and constraints are created successfully on Neo4j. However, when try to do a "merge" or "create" the following error is given (it works fine if I remove "Indexed" from the schema):

Error: Not sure how to validate indexed on name
[1] [1]     at /home/bruno/code/neo4j-node/node_modules/neode/build/Services/Validator.js:273:15
[1] [1]     at Array.forEach (<anonymous>)
[1] [1]     at /home/bruno/code/neo4j-node/node_modules/neode/build/Services/Validator.js:247:25
[1] [1]     at Array.forEach (<anonymous>)
[1] [1]     at BuildValidationSchema (/home/bruno/code/neo4j-node/node_modules/neode/build/Services/Validator.js:165:23)
[1] [1]     at Validator (/home/bruno/code/neo4j-node/node_modules/neode/build/Services/Validator.js:293:16)
[1] [1]     at /home/bruno/code/neo4j-node/node_modules/neode/build/Services/MergeOn.js:38:38
[1] [1]     at processTicksAndRejections (internal/process/task_queues.js:93:5)
[1] [1]     at UserRepo.save (/home/bruno/code/neo4j-node/backend/main-server/src/modules/user/infra/db/user.repo.ts:57:5)
[1] [1]     at CreateUserUseCase.execute (/home/bruno/code/neo4j-node/backend/main-server/src/modules/user/useCases/createUser/CreateUserUseCase.ts:59:7)
[1] [1]     at UserService.createUserService (/home/bruno/code/neo4j-node/backend/main-server/src/modules/user/infra/user.service.ts:41:20)
[1] [1]     at UserResolver.createUser (/home/bruno/code/neo4j-node/backend/main-server/src/modules/user/infra/graphql/resolvers/user.resolver.ts:26:20)
[1] [1]     at target (/home/bruno/code/neo4j-node/node_modules/@nestjs/core/helpers/external-context-creator.js:76:28)
[1] [1]     at /home/bruno/code/neo4j-node/node_modules/@nestjs/core/helpers/external-proxy.js:9:24

My repository class if it is of any help:

@Injectable()
export class UserRepo implements IUserRepo {
  private readonly db: Model<UserToPersistence>;

  constructor(
    @Inject(Neode)
    neode: Neode
  ) {
    this.db = neode.model<UserToPersistence>('User', UserSchema);
  }

  async save(user: User): Promise<void> {
    const userToPersistence = toPersistence(user);

    await this.db.merge(userToPersistence);
  }
}

brvnonascimento avatar Apr 14 '21 13:04 brvnonascimento

I think that might be my bad/inconsistent naming.... have you tried index: true rather than indexed?

adam-cowley avatar Apr 14 '21 13:04 adam-cowley

Yes, I did try ìndex: true and the error goes away. It does not create any index or constraint on Neo4j though, only when ìndexed: true is set.

brvnonascimento avatar Apr 14 '21 13:04 brvnonascimento

Oops! I'll get that sorted

adam-cowley avatar Apr 14 '21 13:04 adam-cowley

I've just had a look at the test and it seems to pass when using index: true - can you share a repo that I can clone and take a look at?

adam-cowley avatar Apr 14 '21 14:04 adam-cowley

@adam-cowley I have the sam error.

Please check this minimal project on link bellow

Github repository user.schema.ts

Error: Not sure how to validate indexed on name
    at /home/alessandro/Workspace/Projects/teste/node_modules/neode/build/Services/Validator.js:273:15
    at Array.forEach (<anonymous>)
    at /home/alessandro/Workspace/Projects/teste/node_modules/neode/build/Services/Validator.js:247:25
    at Array.forEach (<anonymous>)
    at BuildValidationSchema (/home/alessandro/Workspace/Projects/teste/node_modules/neode/build/Services/Validator.js:165:23)
    at Validator (/home/alessandro/Workspace/Projects/teste/node_modules/neode/build/Services/Validator.js:293:16)
    at /home/alessandro/Workspace/Projects/teste/node_modules/neode/build/Services/MergeOn.js:38:38
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async UserService.createUser (/home/alessandro/Workspace/Projects/teste/dist/user-module/user.service.js:30:9)

import { SchemaObject } from 'neode';

const UserSchema: SchemaObject = {
  id: {
    type: 'uuid',
    primary: true,
    required: true,
  },
  name: {
    type: 'string',
    indexed: true,
    required: true,
  },
  email: {
    type: 'string',
    indexed: true,
    unique: true,
    required: true,
  },
  password: { type: 'string', required: true },
  avatar: 'string',
  isFirstAuth: 'boolean',
};

export default UserSchema;

works when I remove the indexes

4lessandrodev avatar Apr 15 '21 20:04 4lessandrodev

Hi, thanks for keeping great work!

When can we use this fixing?

Thanks

akudo7 avatar Nov 27 '21 02:11 akudo7