[英]Graphql - Mutation operation with Apollo Client Angular not working
I am working on a angular app with Graphql, The mutation operation on postman works fine, but when i tried to invoke the same in angular it throws an error as
GraphQL 请求:2:21 1 | 2 | 突变 createHero(item: {$id: ID,: $publisher, String:, $characters: String!, $superhero :String!}){
| ^ 3 | createHero(item: {id: $id, publisher: $publisher, characters: $characters, superhero: $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,
}
});
}
这里有什么问题? 请帮忙。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.