I am trying to implement mutations with a variable. But I get the following error:
"Syntax Error GraphQL request (3:22) Expected Name, found $
2: mutation {
3: createProperty($property) {
^
4: id
"
My schema definitely doesn't say anything about a name, that's why I think this error is so strange.. I also don't think the documentations about graphql / apollo are very good.
Calling the mutation from client:
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,
});
Schema:
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
}
You should mention name of the parameter at first!
mutation CreatePropertyMutatuin($property: propertyInput){
createProperty(property: $property) {
id
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With