"GraphQLError: поле не найдено в типе: 'query_root'" после схемы слияния - PullRequest
0 голосов
/ 21 июня 2019

Я сшил две конечные точки graphql, используя graphql-tools.с одной схемой конечной точки она работает нормально, но с другой схемой выдает эту ошибку "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 голосов
/ 12 июля 2019

это решено! это происходило из-за неправильной авторизации, перенаправленной на 2-ю конечную точку. спасибо

...