I'm new to graphql and am trying to set up a field for one of my users attributes which is more than just a String
or Int
. It should be a reference to an object which with my understanding should be a type
or input
Here's my schema:
schema.graphql
type Mutation {
addOrChangeUserDetails(location: String, coordinates: LocationCoordinateInput): LocationCoordinates
}
type LocationCoordinates {
lat: Int!
long: Int!
}
input LocationCoordinateInput {
coordinates: LocationCoordinates
}
And here is my query
index.js
import gql from 'graphql-tag';
const ADD_OR_CHANGE_USER_DETAILS_MUTATION = gql`
mutation ADD_OR_CHANGE_USER_DETAILS_MUTATION(
$location: String,
$coordinates: LocationCoordinates
) {
addOrChangeUserDetails(
location: $location,
coordinates: $coordinates
) {
location
coordinates
}
}
`;
The error i'm getting is:
Error: The type of LocationCoordinateInput.coordinates must be Input Type but got: LocationCoordinates.
I originally didn't have a separate entry for the LocationCoordinateInput
and thought I could just use the type LocationCoordinates
as my addOrChangeUserDetails
argument but after looking into the issue it seems if I want to refer to something that will be more than just a String
or Int
etc then I need to create a custom input.
Is this the correct approach for creating a "richer" field and if so why might my code not be working?