AndreasFaust / gatsby-source-custom-api

Source data from any API and transform it to (File-)Nodes.
52 stars 25 forks source link

Issue when building pages programmatically #8

Closed vstoyanoff closed 3 years ago

vstoyanoff commented 4 years ago

I am experiencing a problem when building pages programmatically. It appears that the data is missing when I make a query. For example: I feed the plugin with JSON data from an external server. I have an array of deeply nested objects containing data about "Projects". In gatsby-node.js I make a successful query likeso

allProjects {
  edges {
    node {
      slug
      inprogress
      single {
        type
      }
    }
  }
}

And

result.data.allProjects.edges.forEach(({node}) => {
    if (node.slug && !node.inprogress) {
      createPage({
        path: node.slug,
        component: template(node.singleProject.type),
        context: {
          slug: node.slug,
        },
      });
    }
  });

Then when I make query in my template js file for the single project page I get undefined Here is the query

projects(slug: { eq: $slug }) {
      name
      metaTitle
      metaDescription
      slug
      singleProject {
        ...
      }
    }

In development mode when I try to query in the GraphQL console I get only one project as a result instead of like 10 I have in the data. Please help!

dmotan commented 3 years ago

That's probably an issue with your schema definition. Mind posting your schema definition from your gatsby-config.js file?

vstoyanoff commented 3 years ago

It was a long time ago on a project that I am not currently working on. I will close this issue since I can't provide more details.