Search code examples
graphqlschemanodesapollo-servergraphql-tools

"GraphQLError: field not found in type: 'query_root'" after merge schema


I have stitched two graphql endpoint using graphql-tools. with one endpoint schema it is working fine but with another schema it's throwing this error "GraphQLError: field not found in type: 'query_root'". Even if I can see all the schema while introspection.

    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}`);
        });
    };
    ```

Solution

  • I found a solution. It was happening because of the wrong authorization getting forwarded to the 2nd endpoint.