1

有没有办法从 graphql-tools 告诉 makeExecutableSchema 忽略某些指令?

我想用 graphql 查询我的 neo4j 数据库。我还希望能够在 graphql 中指定子类型。有一个名为 graphql-s2s 的库,它向 graphql 添加了子类型。库 neo4j-graphql-js 使用自定义指令(@cyper 和 @relation)来构建增强模式。它需要 typeDefs 或来自 graphql-tools 的 executableSchema。qraphql-s2s 让我可以从包含子类型的模式中创建一个可执行模式。我希望我应该很容易像装饰器模式一样将不同的模式输出相互传递。

不幸的是,这显然不是它的工作原理,因为我收到了很多解析器错误消息,这些消息并不是真正的描述性。

不幸的是,我还没有找到任何 Grandstack 文档,其中显示了如何在其中包含关系和密码的可执行模式上使用 augmentSchema()。

有没有办法做到这一点?

下面是我天真的方法:

const { transpileSchema } = require('graphql-s2s').graphqls2s;
const { augmentSchema } = require('neo4j-graphql-js');
const { makeExecutableSchema} = require('graphql-tools');
const { ApolloServer} = require('apollo-server');

const driver = require('./neo4j-setup');

/** The @relation and @cypher directives don't make any sense here they are 
just for illustration of having directives that make sense to
'augmentSchema' and not to 'makeExecutableSchema' **/  

const schema = `
type Node {
    id: ID!
}

type Person inherits Node {
    firstname: String
    lastname: String @relation(name: "SOUNDS_LIKE", direction: "OUT") 
}

type Student inherits Person {
    nickname: String @cypher(
      statement: """ MATCH (n:Color)...some weird cypher query"""
    )
}

type Query {
  students: [Student]
}
`

const resolver = {
        Query: {
            students(root, args, context) {
                // Some dummy code
                return [{ id: 1, firstname: "Carry", lastname: "Connor", nickname: "Cannie" }]
            }
        }
    };

const executabledSchema = makeExecutableSchema({
  typeDefs: [transpileSchema(schema)],
  resolvers: resolver
})

const schema = augmentSchema(executabledSchema)

const server = new ApolloServer({ schema, context: { driver } });

server.listen(3003, '0.0.0.0').then(({ url }) => {
  console.log(`GraphQL API ready at ${url}`);
});
4

0 回答 0