kolossal-io / gatsby-source-mock

This plugin allows you to mock GraphQL data in Gatsby sites using Faker.js
MIT License
2 stars 0 forks source link

How to add mock data to nested type? #1

Open yenchieh opened 2 years ago

yenchieh commented 2 years ago

Hello, I couldn't figure out how to do mock data on nested type. For example: The query:

      allPost(sort: { fields: [date] }) {
        nodes {
          title
          excerpt
          content
          slug
          categories {
            nodes {
              slug
            }
          }
        }
      }

The two mock I created:

    {
      resolve: `gatsby-source-mock`,
      options: {
        schema: {
          slug: (faker) => faker.lorem.slug(),
          'categories:[Category!]!': [
            {
              slug: (faker) => faker.lorem.slug(),
            }
          ],
          date: (faker) => faker.date.between('2020-01-01T00:00:00.000Z', '2030-01-01T00:00:00.000Z'),
        },
        type: `LearnPost`,
        count: 5,
      }
    },
    {
      resolve: `gatsby-source-mock`,
      options: {
        schema: {
          slug: (faker) => faker.lorem.slug(),
        },
        type: `Category`,
        count: 2,
      }
    },

But it doesn't create the structure with categories.nodes.slug, it only generates categories.slug.

Thanks

marijoo commented 2 years ago

This isn't supported right now, I think, but I'd have to investigate further.