import { makeExecutableSchema } from 'graphql-tools';
const fish = { length:50 },
rope = { length:100 };
const typeDefs = `
type Query {
rope: Rope!
fish: Fish!
}
type Mutation {
increase_fish_length: Fish!
increase_rope_length: Rope!
}
type Rope {
length: Int!
}
type Fish {
length: Int!
}
`;
const resolvers = {
Mutation: {
increase_fish_length: (root, args, context) => {
fish.length++;
return fish;
},
increase_rope_length: (root, args, context) => {
rope.length++;
return rope;
}
}
};
export const schema = makeExecutableSchema({ typeDefs, resolvers });
上面的例子运行良好,但我想使用一个变异名称increase_length,而不是increase_fish_length和increase_rope_length。
我尝试使用斜杠将突变命名为Fish/increase_length和Rope/increase_length,但不起作用。(仅/_A-Za-z*/可用。)
GraphQl是否支持命名空间的解决方案?
发布于 2018-08-18 22:23:41
Graphql不支持名称空间之类的东西
发布于 2018-08-21 09:08:59
我一直在玩弄一些关于名称空间的想法。如果你的typeDefinitions看起来像这样会怎么样:
type Mutation {
increase_length: IncreaseLengthMutation!
}
type IncreaseLengthMutation {
fish: Fish!
rope: Rope!
}
你的解算器看起来是这样的:
const resolvers = {
Mutation: {
increase_Length: () => {
return {}
}
},
IncreaseLengthMutation {
fish: (root, args, context) => {
fish.length++;
return fish;
},
rope: (root, args, context) => {
rope.length++;
return rope;
}
}
};
最大的缺点是不可靠的突变解析器,它返回一个空数组。然而,它必须存在,这样它才能级联到其他突变。
https://stackoverflow.com/questions/51909282
复制相似问题