如何在JavaScript/TypeScript中格式化此QraphQL变体?
我有一个变种,当我在浏览器中的GraphiQL中调用它时,它的工作原理是这样的如何在JavaScript/TypeScript中格式化此QraphQL变体?,javascript,typescript,graphql,Javascript,Typescript,Graphql,我有一个变种,当我在浏览器中的GraphiQL中调用它时,它的工作原理是这样的 mutation { initGroups(groups: [{name: "Home", icon: 1, userid: "100"}, {name: "Work", icon: 2, userid: "100"}]) { name } } export const INIT_GROUPS = gql` muta
mutation {
initGroups(groups: [{name: "Home", icon: 1, userid: "100"}, {name: "Work", icon: 2, userid: "100"}]) {
name
}
}
export const INIT_GROUPS = gql`
mutation initGroups($groups: [GroupInputType!]) {
initGroups(groups: $groups) {
name
}
这是我的服务器文件夹中的变异定义
export const INIT_GROUPS = {
type: new GraphQLList(GroupType),
args: {
groups: { type: new GraphQLList(GroupInputType) }
},
async resolve(parent: any, args: any) {
const { groups } = args
await Groups.insert(groups)
}
}
这里是我用于突变的类型定义
export const GroupType = new GraphQLObjectType({
name: "Group",
fields: () => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
icon: { type: GraphQLInt },
userid: { type: GraphQLString }
})
})
export const GroupInputType = new GraphQLInputObjectType({
name: "GroupInput",
fields: () => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
icon: { type: GraphQLInt },
userid: { type: GraphQLString }
})
})
但我不知道如何在我的客户机文件夹文件中定义它。为了说明我的意思,这里有一个例子,说明我是如何在我的客户机文件夹中定义了一个不同的变种(这个变种在运行时被调用时可以正常工作)
当然,这一点更简单。我似乎不知道如何像上面的例子那样定义INIT_群。在运行时调用时,我尝试的所有操作都会抛出一个错误。现在我有这样的东西
mutation {
initGroups(groups: [{name: "Home", icon: 1, userid: "100"}, {name: "Work", icon: 2, userid: "100"}]) {
name
}
}
export const INIT_GROUPS = gql`
mutation initGroups($groups: [GroupInputType!]) {
initGroups(groups: $groups) {
name
}