有一个我没有的graphql端点,但它提供了一个公共端点。我希望用graphiql来反思它。我对graphql完全陌生,所以我甚至不知道这种事情是否可能。用graphiql检查远程graphql端点
我有本地运行的graphiql example,并且正在修改server.js以尝试使其工作。在其他SO线程闲逛已经得到了我到这地步?
var introspectionQuery = require('graphql/utilities').introspectionQuery;
var request = require('sync-request');
var url = 'http://endpoint.com/graphql';
var response = request('POST', url, { qs: { query: introspectionQuery } });
var schema = JSON.parse(response.body.toString('utf-8'));
// herein lies the rub
schema = new GraphQLSchema(schema.data.__schema);
var app = express();
app.use(express.static(__dirname));
app.use('/graphql', graphqlHTTP(() => ({
schema: schema,
})));
app.listen(8080);
此代码在GraphQLSchema构造炸毁,试图使一个模式指出,自省查询。显然这不是正确的方法?
工作正常!我只需要做'buildClientSchema(introspectionResult.data)'。 –
那么接下来的问题就是如何使用graphiql将查询发送回该端点...... –
为此,您可以查看我们在此处的示例index.html代码:https://github.com/graphql/ graphiql/blob/master/example/index.html#L95 –