我试图用变量实现突变.但是我收到以下错误:
"Syntax Error GraphQL request (3:22) Expected Name, found $
2: mutation {
3: createProperty($property) {
^
4: id
"
Run Code Online (Sandbox Code Playgroud)
我的架构肯定没有说出一个名字,这就是为什么我认为这个错误是如此奇怪..我也不认为关于graphql/apollo的文档是非常好的.
从客户端调用变异:
const property = {
title: 'First house',
cost: 849,
bedrooms: 3,
bathrooms: 2,
car_spaces: 1,
house_size: 60,
};
const createPropertyQuery =
graphql(gql`
mutation {
createProperty($property) {
id
}
}
`, {
options: {
variables: {
property,
},
},
});
const { data } = await apolloClient.query({
query: createPropertyQuery,
});
Run Code Online (Sandbox Code Playgroud)
架构:
type Property {
title: String!
cost: Float
user: User
bedrooms: Int!
bathrooms: Int!
car_spaces: Int!
house_size: Int!
}
input propertyInput {
title: String!
cost: Float
bedrooms: Int!
bathrooms: Int!
car_spaces: Int!
house_size: Int!
}
type RootMutation {
createProperty (
property: propertyInput
): Property
}
Run Code Online (Sandbox Code Playgroud)
小智 10
你应该首先提一下参数的名称!
mutation CreatePropertyMutatuin($property: propertyInput){
createProperty(property: $property) {
id
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22733 次 |
最近记录: |