【问题标题】:Graphql - Mutation operation with Apollo Client Angular not workingGraphql - Apollo Client Angular 的变异操作不起作用
【发布时间】:2022-08-24 17:38:07
【问题描述】:

我正在使用 Graphql 开发一个角度应用程序,邮递员的突变操作工作正常, 但是当我尝试在角度中调用相同的内容时,它会引发错误

GraphQL 请求:2:21 1 | 2 |突变 createHero(item: {$id : ID!, $publisher : String!, $characters : String!, $superhero :String!}){
| ^ 3 | createHero(项目:{id:$id,发布者: $publisher,人物:$characters,超级英雄:$superhero}) GraphQLError:语法错误:应为 \"$\",找到名称 \"item\"。

这是工作请求

mutation{
  createHero (item:{ id:\"test1\", alter_ego:\"hero\", first_appearance:\"cosmos\", publisher:\"azure\", superhero:\"test\"}) {
     id
     superhero
      publisher
      characters
      alter_ego
      first_appearance
  }
}

这是Angular应用程序上的代码,

const post_SaveHero = gql`
mutation createHero(item: {$id : ID!, $publisher : String!, $characters : String!, $superhero :String!}){
  createHero(item: {id: $id, publisher : $publisher , characters : $characters , superhero : $superhero} )
 {
  superhero
}
}`;

  addHero(hero: Hero) {
    return this.apollo.mutate({
      mutation: post_SaveHero,
      variables: {
        $publisher: hero.publisher,
        $characters: hero.characters,
        $superhero: hero.superhero,
        $id : hero.id,
        $alter_ego : hero.alter_ego,
        $first_appearance : hero.first_appearance,
        
      }
    });
  }

这里有什么问题?请帮忙。

    标签: angular graphql apollo-client


    【解决方案1】:

    尝试设置id: String! 我还建议您在邮递员验证中添加变量

    【讨论】:

      猜你喜欢
      • 2020-02-14
      • 1970-01-01
      • 2021-04-17
      • 1970-01-01
      • 2020-07-15
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      相关资源
      最近更新 更多