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
}
}
}
The healthcareWorkers Schema:
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
}
}
}
The healthcareWorkers Schema:
Share Improve this question asked May 13, 2020 at 9:03 krishnanspacekrishnanspace 4331 gold badge7 silver badges18 bronze badges1 Answer
Reset to default 1firstname
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
}
}
}
`;