Javascript 如何解决GraphQL中的命名冲突?
上面的例子运行得很好,但我想使用一个突变名称来增加长度,而不是增加鱼的长度和绳子的长度 我试着用斜杠来命名鱼/增加长度和绳子/增加长度,但没用。(只有/[[u A-Za-z][[u 0-9A-Za-z]*/可用。)Javascript 如何解决GraphQL中的命名冲突?,javascript,graphql,graphql-tools,Javascript,Graphql,Graphql Tools,上面的例子运行得很好,但我想使用一个突变名称来增加长度,而不是增加鱼的长度和绳子的长度 我试着用斜杠来命名鱼/增加长度和绳子/增加长度,但没用。(只有/[[u A-Za-z][[u 0-9A-Za-z]*/可用。) GraphQl支持名称空间的任何解决方案吗?GraphQl不支持类似名称空间的东西我一直在玩弄有关名称空间的一些想法。如果您的类型定义如下所示: import { makeExecutableSchema } from 'graphql-tools'; const fish = {
GraphQl支持名称空间的任何解决方案吗?GraphQl不支持类似名称空间的东西我一直在玩弄有关名称空间的一些想法。如果您的类型定义如下所示:
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 });
type Mutation {
increase_length: IncreaseLengthMutation!
}
type IncreaseLengthMutation {
fish: Fish!
rope: Rope!
}
您的解析器如下所示:
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 });
type Mutation {
increase_length: IncreaseLengthMutation!
}
type IncreaseLengthMutation {
fish: Fish!
rope: Rope!
}
最大的缺点是不可靠的变异解析器返回空数组。但是,它必须存在,才能级联到其他突变。Yeah~!我过去常常把这个想法应用到查询中。我得考虑一下。谢谢分享你的想法!