new Neo4jGraphQL({ typeDefs, driver }) 导致未知指令错误
new Neo4jGraphQL({ typeDefs, driver }) causes Unknown directive error
我正在尝试创建一个新的 GRANDstack 应用程序。数据库已经存在,所以我使用了“infer-schema.js”脚本来生成 gql 模式。当我 运行 api 服务器时,出现以下错误:
Error: Unknown directive "@relation".
13:42:38 api | Unknown directive "@relation".
这是一个新的 GRANDstack 项目 - 以下内容未受影响 index.js:
const driver = neo4j.driver(
process.env.NEO4J_URI || 'bolt://localhost:7687',
neo4j.auth.basic(
process.env.NEO4J_USER || 'neo4j',
process.env.NEO4J_PASSWORD || 'neo4j'
)
)
/*
* Create an executable GraphQL schema object from GraphQL type definitions
* including autogenerated queries and mutations.
* Read more in the docs:
* https://neo4j.com/docs/graphql-manual/current/
*/
const neoSchema = new Neo4jGraphQL({ typeDefs, driver })
使用架构:
type Incredient {
_id: ID!
name: String!
recipes: [Recipe] @relation(name: "HAS", direction: IN)
}
type Product {
_id: ID!
name: String!
has_offer: [Offer] @relation(name: "HAS_OFFER", direction: OUT)
HAS_OFFER_rel: [HAS_OFFER]
has_quantity: [Quantity] @relation(name: "HAS_QUANTITY", direction: OUT)
HAS_QUANTITY_rel: [HAS_QUANTITY]
}
type Offer {
_id: ID!
newPrice: Float!
normalPrice: Float!
products: [Product] @relation(name: "HAS_OFFER", direction: IN)
}
type Quantity {
_id: ID!
name: String!
products: [Product] @relation(name: "HAS_QUANTITY", direction: IN)
}
type Recipe {
_id: ID!
name: String!
has: [Incredient] @relation(name: "HAS", direction: OUT)
HAS_rel: [HAS]
}
type HAS @relation(name: "HAS") {
from: Recipe!
to: Incredient!
amount: Float!
unit: String!
}
type HAS_OFFER @relation(name: "HAS_OFFER") {
from: Product!
to: Offer!
discount: Float!
}
type HAS_QUANTITY @relation(name: "HAS_QUANTITY") {
from: Product!
to: Quantity!
quantity: Float!
}
您不能为 @neo4j/graphql
(官方 Neo4j GraphQL 库)使用推断模式,它只能与已弃用的 neo4j-graphql-js
一起使用。您正在尝试将 neo4j-graphql-js
兼容模式放入 @neo4j/graphql
。您应该将 @relation
更改为 @relationship
,关系属性请参考 this。
我正在尝试创建一个新的 GRANDstack 应用程序。数据库已经存在,所以我使用了“infer-schema.js”脚本来生成 gql 模式。当我 运行 api 服务器时,出现以下错误:
Error: Unknown directive "@relation".
13:42:38 api | Unknown directive "@relation".
这是一个新的 GRANDstack 项目 - 以下内容未受影响 index.js:
const driver = neo4j.driver(
process.env.NEO4J_URI || 'bolt://localhost:7687',
neo4j.auth.basic(
process.env.NEO4J_USER || 'neo4j',
process.env.NEO4J_PASSWORD || 'neo4j'
)
)
/*
* Create an executable GraphQL schema object from GraphQL type definitions
* including autogenerated queries and mutations.
* Read more in the docs:
* https://neo4j.com/docs/graphql-manual/current/
*/
const neoSchema = new Neo4jGraphQL({ typeDefs, driver })
使用架构:
type Incredient {
_id: ID!
name: String!
recipes: [Recipe] @relation(name: "HAS", direction: IN)
}
type Product {
_id: ID!
name: String!
has_offer: [Offer] @relation(name: "HAS_OFFER", direction: OUT)
HAS_OFFER_rel: [HAS_OFFER]
has_quantity: [Quantity] @relation(name: "HAS_QUANTITY", direction: OUT)
HAS_QUANTITY_rel: [HAS_QUANTITY]
}
type Offer {
_id: ID!
newPrice: Float!
normalPrice: Float!
products: [Product] @relation(name: "HAS_OFFER", direction: IN)
}
type Quantity {
_id: ID!
name: String!
products: [Product] @relation(name: "HAS_QUANTITY", direction: IN)
}
type Recipe {
_id: ID!
name: String!
has: [Incredient] @relation(name: "HAS", direction: OUT)
HAS_rel: [HAS]
}
type HAS @relation(name: "HAS") {
from: Recipe!
to: Incredient!
amount: Float!
unit: String!
}
type HAS_OFFER @relation(name: "HAS_OFFER") {
from: Product!
to: Offer!
discount: Float!
}
type HAS_QUANTITY @relation(name: "HAS_QUANTITY") {
from: Product!
to: Quantity!
quantity: Float!
}
您不能为 @neo4j/graphql
(官方 Neo4j GraphQL 库)使用推断模式,它只能与已弃用的 neo4j-graphql-js
一起使用。您正在尝试将 neo4j-graphql-js
兼容模式放入 @neo4j/graphql
。您应该将 @relation
更改为 @relationship
,关系属性请参考 this。