首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在GrandStack中设置关系类型

在GrandStack中设置关系类型
EN

Stack Overflow用户
提问于 2021-02-25 14:51:17
回答 1查看 126关注 0票数 0

我正在尝试在Grandstack中设置关系类型。我在让事情正常运行时遇到了问题。即使我将指南复制到我的项目中并尝试运行它...事情并不是这样的。这是他们在https://grandstack.io/docs/guide-graphql-schema-design上的内容

代码语言:javascript
复制
type Actor {
    actorId: ID!
    name: String
    movies: [Movie] @relation(name: "ACTED_IN", direction: OUT)
}

type Movie {
    movieId: ID!
    title: String
    description: String
    year: Int
    actors(limit: Int = 10): [Actor] @relation(name: "ACTED_IN", direction: IN)
    similarMovies(limit: Int = 10): [Movie] @cypher(statement: """
        MATCH (this)<-[:ACTED_IN]-(:Actor)-[:ACTED_IN]->(rec:Movie)
        WITH rec, COUNT(*) AS score ORDER BY score DESC
        RETURN rec LIMIT $limit
    """)
}

type User {
    userId: ID!
    name: String
    rated: [Rated]
}

type Rated @relation(name: "RATED") {
    from: User
    to: Movie
    rating: Float
    review: String
}

问题是,当我运行这个命令时,我得到了以下错误:

代码语言:javascript
复制
ApolloError: The 'from' argument of the @relation directive on the _UserRated type is "User", but a "User" field is not defined.
    at validateRelationTypeNodeField (/Users/kennyv/git/skoutal-server/node_modules/neo4j-graphql-js/dist/augment/types/relationship/relationship.js:221:13)
    at validateRelationTypeDirective (/Users/kennyv/git/skoutal-server/node_modules/neo4j-graphql-js/dist/augment/types/relationship/relationship.js:183:5)

不确定为什么它认为用户字段未定义。这是我的server.js文件

代码语言:javascript
复制
require("dotenv").config();
const { ApolloServer, PubSub } = require("apollo-server");
const jwt = require("jsonwebtoken");
const neo4j = require("neo4j-driver");
const { augmentSchema, makeAugmentedSchema } = require("neo4j-graphql-js");
const typeDefs = require("./graphql/typeDefs.js");
const resolvers = require("./graphql/resolvers");

require("console-stamp")(console, { pattern: "mm/dd/yyyy HH:MM:ss.l" });
// Create an instance of Express

const pubsub = new PubSub();
const PORT = process.env.PORT || 5000;
const schema = makeAugmentedSchema({
  typeDefs,
  resolvers,
  // config: {
  //   query: true,
  //   mutation: true,
  // },
});
const augmentedSchema = augmentSchema(schema);

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 server = new ApolloServer({
  schema: schema,
  context: ({ req }) => {
    const token = req?.headers?.authorization?.slice(7);
    let userId;
    if (token) {
      const decoded = jwt.verify(token, process.env.APP_SECRET);
      userId = decoded.id;
    }
    return {
      cypherParams: { userId },
      driver,
      neo4jDatabase: process.env.NEO4J_DATABASE,
      req,
      pubsub,
    };
  },
});
代码语言:javascript
复制
"apollo-server": "^2.20.0",
"graphql": "^15.5.0",
"neo4j-driver": "^4.2.2",
"neo4j-graphql-js": "^2.19.2",
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-25 15:09:18

我不小心跑了

代码语言:javascript
复制
const augmentedSchema = augmentSchema(schema);

在我已经运行过的模式上

代码语言:javascript
复制
makeAugmentedSchema({
  typeDefs,
  resolvers,
  // config: {
  //   query: true,
  //   mutation: true,
  // },
});

这是一个远离makeExecutableSchema的工件,我不得不删除它,因为它会导致问题。

即:

代码语言:javascript
复制
Error: Unknown directive "@relation".

Unknown directive "@relation".

Unknown directive "@cypher".

Unknown directive "@relation".

Unknown directive "@relation".

Unknown directive "@relation".

因此,当我注释掉augmentSchema时,一切都开始正常工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66363678

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档