"GraphQLError: field not found in type: 'query_root'" after merge schema
"GraphQLError: field not found in type: 'query_root'" after merge schema
我已经使用 graphql-tools 拼接了两个 graphql 端点。
对于一个端点模式,它工作正常,但对于另一种模式,它会抛出此错误
"GraphQLError: field not found in type: '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}`);
});
};
```
我找到了解决办法。这是因为错误的授权被转发到第二个端点。
我已经使用 graphql-tools 拼接了两个 graphql 端点。 对于一个端点模式,它工作正常,但对于另一种模式,它会抛出此错误 "GraphQLError: field not found in type: '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}`);
});
};
```
我找到了解决办法。这是因为错误的授权被转发到第二个端点。