合并架构后出现“ GraphQLError:在类型:'query_root'中找不到字段”

时间:2019-06-21 11:46:49

标签: graphql schema nodes apollo-server graphql-tools

我使用graphql-tools缝合了两个graphql端点。 与一个端点模式,它工作正常,但与另一个模式,它抛出此错误 “ GraphQLError:在类型'query_root'中找不到字段”。 即使我可以在内省时看到所有架构。

const createRemoteExecutableSchemas = async () => {
    let schemas = [];
    for (let api of graphqlApis) {
        const http =  http_link.HttpLink({
            uri: api.uri,
            fetch:fetch
        });
        const link1 = setContext.setContext((request, previousContext) => {
            return {
                headers:{authorization: previousContext.graphqlContext.headers.authorization}
            }
        }).concat(http);

        const link2 = setContext.setContext((request, previousContext) => ({
            headers: {
                'x-hasura-admin-secret': api.secret
            }
          })).concat(http);
        const remoteSchema = await gtool.introspectSchema(link2);
        const remoteExecutableSchema =  gtool.makeRemoteExecutableSchema({
            schema: remoteSchema,
            link:link1
        });
        schemas.push(remoteExecutableSchema);
    }
    return schemas;
};

const createNewSchema = async () => {
    const schemas = await createRemoteExecutableSchemas();
    return gtool.mergeSchemas({
        schemas:schemas
    });

};

const runServer = async () => {
    const schema = await createNewSchema();
    const server =  new ap_server.ApolloServer({
        schema:schema,
        context: ({ req }) => {
            return {
                "headers": req.headers
            }
          }
    });
    server.listen().then(({url}) => {
        console.log(`Running at ${url}`);
    });
};

1 个答案:

答案 0 :(得分:0)

问题解决了! 这是由于错误的授权转发到第二个端点而发生的。 谢谢