Imagine we’ve got a one-to-many relationship:
type Project {
tasks: [Task!]
}
type Task {
dueDate: String!
}
When querying this relationship, the Fauna GQL docs show one must use data
to access the relations’ data. For example:
query FindProject {
getProjectByID(id: 804140812042) {
tasks {
data {
dueDate
}
}
}
}
In server-side JS the response might provide the tasks data like so:
const tasks = res.data.project.tasks.data;
Is there a recommendation for how to align this data structure, with the data
property inserted, when using a similar Schema on the frontend (e.g. a React app calling an Apollo server)? An error like Expected Iterable, but did not find one for field "Project.tasks".
is seen if one does not parse data returned by Fauna before it’s sent to the GraphQL server and onwards to the frontend.
Options I can think of include:
- Somehow adding a
data
field to relevant object types in the frontend schema - Parsing responses from the Fauna GraphQL API to unnest/remove the
data
property before sending data to the frontend (seems dodgy!) - Just accepting there may be extra
data
properties throughout the code
Thanks!