-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
Description
I am trying to do a mutation on Graphql. I want to add another object in my query and mutation. My root query works fine but I had trouble with mutation. I am getting an error. This is the error: "The type of Mutation.addRestaurant(location:) must be Input Type but got: LocationType."
This is my restaurant query
const restaurantname = new GraphQLObjectType({
name: "RestaurantType",
description: "This is Helsinki's Restuarent",
fields: () => ({
name: { type: GraphQLString },
image: { type: GraphQLString },
address: { type: GraphQLString },
info_url: { type: GraphQLString },
location: { // This is locationtype
type: location,
resolve(parents, args) {
return parents;
}
}
})
});
This is my locationtype object, where I added in restaurant type.
const location = new GraphQLObjectType({
name: "LocationType",
description: "Helsinki's locations with lat and long",
fields: () => ({
lat: { type: GraphQLFloat },
long: { type: GraphQLFloat }
})
});
This is my root query and it works fine:
const query = new GraphQLObjectType({
name: "Rootquery",
description: "This is Rootquery",
fields: () => {
return {
restaurant: {
type: restaurantname,
args: {
name: { type: GraphQLString }
},
resolve(parents, args) {
//return restaurant.models.restaurant.find({ where: args });
return parents;
}
}
};
}
});
This is the mutation which I don't know how to add locationtype object:
const mutation = new GraphQLObjectType({
name: "Mutation",
fields: () => {
return {
addRestaurant: {
type: restaurantname,
args: {
name: { type: new GraphQLNonNull(GraphQLString) },
image: { type: new GraphQLNonNull(GraphQLString) },
address: { type: new GraphQLNonNull(GraphQLString) },
info_url: { type: new GraphQLNonNull(GraphQLString) },
location: { type: new GraphQLNonNull(location) } //
},
resolve(parents, args) {
let restaurantData = new restaurant({
name: args.name,
image: args.image,
address: args.address,
info_url: args.info_url,
location: args.location
});
restaurantData.save();
}
}
};
}
});
This is second time Github issue. So, It looks mess. I am sorry for that.