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

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

Open
brvnonascimento opened this issue Apr 14, 2021 · 6 comments

Comments

@brvnonascimento
Copy link

brvnonascimento commented Apr 14, 2021

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);
  }
}
@adam-cowley
Copy link
Owner

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

@brvnonascimento
Copy link
Author

brvnonascimento commented Apr 14, 2021

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.

@adam-cowley
Copy link
Owner

Oops! I'll get that sorted

@adam-cowley
Copy link
Owner

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?

@4lessandrodev
Copy link

4lessandrodev commented Apr 15, 2021

@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 added a commit to 4lessandrodev/neode that referenced this issue Apr 15, 2021
error when uses with typescript typed as SchemaObject
adam-cowley#149
@akudo7
Copy link

akudo7 commented Nov 27, 2021

Hi, thanks for keeping great work!

When can we use this fixing?

Thanks

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

4 participants