AndreasFaust / gatsby-source-custom-api

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

How does it discover individual objects? #40

Open dbx834 opened 2 years ago

dbx834 commented 2 years ago

Hello... Thanks for making this package, it's really useful. I was looking at the code and was wondering how does it discover individual objects given an endpoint?

Suppose there are these two books that the API publishes data on,

https://api.example.com/json/books/1
https://api.example.com/json/books/2

Given a configuration,

{
  resolve: 'gatsby-source-custom-api',
  options: {
    url: 'https://api.example.com/json',
    imageKeys: ['images'],
    rootKey: 'books',
    schemas: {
      book: `
        id: Int
        title: String
        isbn: String
      `,
    },
  },
}

How does it discover the two objects? I wasn't able to make it out from the codebase. If you think this might be also useful for others, maybe it can be added in the documentation. If I'm able to understand it, I'll contribute a PR. Thanks.

dbx834 commented 2 years ago

I observe that perhaps my understating is not correct. Is it so that it expects the endpoint to publish an array of object, each object being a document?