【发布时间】:2019-10-20 00:57:57
【问题描述】:
我有一个包含以下现有路由的 GraphQL 和 Express 项目:
// ...
const graphiqlExpress = require('graphql-server-express').graphiqlExpress;
const graphqlExpress = require('graphql-server-express').graphqlExpress;
const makeExecutableSchema = require('graphql-tools').makeExecutableSchema;
// ...
const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
// ...
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema }));
app.use(
'/graphiql',
graphiqlExpress({
endpointURL: '/graphql',
})
);
我在http://localhost:3030/graphql?query={regions(countries:["FR"],level:0){...} 上获得 GET 后的结果看起来像正常的 GraphQL 响应:
{
"data": {
"regions": [
{
"type": "FeatureCollection",
"features": [
...
...
]
}
]
}
}
有没有办法将响应转换为更像有效的 GeoJSON 格式? (没有 "data:{ }" 并且没有我的查询名称等)例如:
{
"type": "FeatureCollection",
"features": [
...
...
]
}
我已经考虑过使用 middleare(但如何使用?)和/或规范化器,例如 graphql-normalizr(但我没有不知道如何用 Express 插入)
【问题讨论】:
标签: javascript node.js express graphql