我正在制作一个GRANDStack应用程序,所以我使用neo4j和graphql,
在我的schema.graphql文件中有这样的类型:
type User {
userId: ID!
username: String! @unique
mail: String! @unique
password: String! @private
}但是我仍然可以用相同的
当我在这里查看neo4j文档时,我知道这是可能的:https://neo4j.com/docs/graphql-manual/current/directives/#_unique
但目前我发现的唯一方法是在我的数据库中手动执行这样的操作:
CREATE CONSTRAINT ON (u:User) ASSERT u.mail IS UNIQUE;但这不是个好主意,我希望这是自动的
我认为我的package.json也是最新的:
{
"name": "grand-stack-starter-api",
"version": "0.0.1",
"description": "API app for GRANDstack",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start:dev": "./node_modules/.bin/nodemon --watch src --ext js,graphql --exec babel-node src/index.js",
"build": "babel src --out-dir build && shx cp .env build 2>/dev/null || : && shx cp src/schema.graphql build",
"now-build": "babel src --out-dir build && shx cp src/schema.graphql build",
"start": "npm run build && node build/index.js",
"seedDb": "./node_modules/.bin/babel-node src/seed/seed-db.js"
},
"author": "William Lyon",
"license": "MIT",
"dependencies": {
"@apollo/client": "^3.2.5",
"@neo4j/graphql": "^2.4.0",
"apollo-server": "^3.5.0",
"apollo-server-lambda": "^2.19.0",
"csv-parse": "^4.10.1",
"dotenv": "^7.0.0",
"graphql": "^16.0.1",
"neo4j-driver": "^4.4.0",
"node-fetch": "^2.6.0",
"react": "^16.13.1"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/node": "^7.8.7",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@babel/preset-react": "^7.9.4",
"@babel/preset-typescript": "^7.9.0",
"@babel/runtime-corejs3": "^7.9.2",
"babel-plugin-auto-import": "^1.0.5",
"babel-plugin-module-resolver": "^4.0.0",
"cross-env": "^7.0.2",
"nodemon": "^1.19.1",
"shx": "^0.3.2"
}
}发布于 2021-11-23 14:24:14
因此,没有更新文档。
要解决这个问题,我首先必须遵循以下命令:https://neo4j.com/docs/graphql-manual/current/type-definitions/constraints/#type-definitions-constraints-unique
解决方案是添加这是错误的
await neoSchema.assertConstraints({ options: { create: true }});我和在neo4j工作的人交谈过,他们的意见不一致,的右函数是:
await neoSchema.assertIndexesAndConstraints({ options: { create: true }});如果像我一样,您不能等待,因为您的代码不在函数中,您可以使用.then执行如下操作:
const neoSchema = new Neo4jGraphQL({
...
})
neoSchema
.assertIndexesAndConstraints({ options: { create: true } })
.then(() => {
const server = new ApolloServer({
...
app.listen({ host, port, path }, () => {
console.log(`GraphQL server ready at http://${host}:${port}${path}`)
})
})https://stackoverflow.com/questions/70065096
复制相似问题