首页 > 解决方案 > 从驱动程序推断出架构后,如何合并架构?

问题描述

我使用 inferSchema 直接从 neo4j 数据库生成 GraphQL 类型定义,如下所示:

const inferAugmentedSchema = driver => {
    return inferSchema(driver).then(result => {
        return makeAugmentedSchema({
            typeDefs: result.typeDefs,
            config: {
                mutation: false
            }
        });
    })
};

现在我需要将上面的模式与另一个模式合并,这样我就可以扩展一个类型,但是每次我尝试都会引发这个错误:

初始化 Neo4j 架构
这可能需要一些时间,具体取决于数据库 pathToProject\node_modules\graphql\validation\validate.js:124 的大小
throw new Error(errors.map(function (error) { ^ Error: Cannot extend type " Municipio”,因为它没有定义。

这是我尝试合并它的完整代码:

    const driver = neo4j.driver(
    process.env.URL,
    neo4j.auth.basic(process.env.NEO4J_USER, process.env.NEO4J_PWD)
);

 const inferAugmentedSchema = driver => {
    return inferSchema(driver).then(result => {
        return makeAugmentedSchema({
            typeDefs: result.typeDefs,
            config: {
                mutation: false
            }
        });
    })
};

const types = [
    inferAugmentedSchema,
    municipioExtended,
];

const mergedSchema = mergeSchemas({
    schemas: [typeDefs, municipioExtended]
});

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

server.listen().then(({url}) => {
    console.log(`server ready at ${url}`)
});

标签: graphqlapollo-servergraphql-toolsneo4j-driverneo4j-graphql-js

解决方案


推荐阅读