I'm new to Gridsome (and GraphQL) and I'd like to build the following. I have a n-to-n relationship of Employees to Projects and would like to generate a page per employee, listing all the projects this employee worked on. I create the pages using the Pages API, which is the part that does work. However, passing the context / listing the projects per employee doesn't work.
All the data is in markup and looks like this: Projects:
---
name: "Project 1"
...
---
Employees:
---
name: "Employee 1"
projects:
- name: "Project 1"
- name: "Project 2"
---
gridsome.server.js:
api.createPages(async ({ graphql, createPage }) => {
const { data } = await graphql(`{
allEmployee {
edges {
node {
id
name
projects {
name
}
}
}
}
}`)
data.allEmployee.edges.forEach(({ node }) => {
createPage({
path: `/${node.name}`,
component: './src/templates/Employee.vue',
context: {
id: node.id,
name: node.name,
projectsWorkedOn: node.projects
}
})
})
})
page-query in Employee.vue:
<page-query>
query EmployeeProjects ($projectsWorkedOn: [String]) {
allProject (filter: { name: { in: $projectsWorkedOn } } ) { //how to use the $projectsWorkedOn object here?
edges {
node {
id
name
}
}
}
}
</page-query>
Now that doesn't work, at the very least I'm trying to use the object as an array, but I'm sure there are other things wrong with it as well. I hope someone can point me in the right direction, unfortunately Gridsome documentation is quite shallow.