Reputation: 423
So I am running a gql query on a React app and passing some default variables. But when the query runs I'm getting this error:
Error: GraphQL error: Validation error of type FieldUndefined: Field 'firstname' in type 'HealthcareWorkersPage' is undefined @ 'healthcareWorkers/firstname'
This is the query in the .js file :
export const GET_PROFILES = gql`query healthcareWorkers($pageNo: Int = 0, $pageSize:Int = 6) {
healthcareWorkers(pageNo: $pageNo, pageSize: $pageSize) {
firstname
}
}`;
Earlier the above query was :
export const GET_PROFILES = gql`query {
healthcareWorkers($pageNo: Int = 0, $pageSize:Int = 6) {
healthcareWorkers(pageNo: $pageNo, pageSize: $pageSize) {
firstname
}
}
}`;
Notice the {}
after the query keyword. But in this case I got an error saying Syntax Error: Expected Name, found $
I use this query on the playground and it works without any issues:
query{
healthcareWorkers(pageNo: 1, pageSize:6) {
healthcareWorkers {
firstname
}
}
}
Upvotes: 1
Views: 14733
Reputation: 4540
firstname
field lives inside healthcareWorkers
type. Try this query:
export const GET_PROFILES = gql`
query healthcareWorkers($pageNo: Int = 0, $pageSize: Int = 6) {
healthcareWorkers(pageNo: $pageNo, pageSize: $pageSize) {
healthcareWorkers {
firstname
}
}
}
`;
Upvotes: 1