thinhle-agilityio / gatsby-source-apiserver

A gatsby source plugin for pulling data from api server.
63 stars 34 forks source link

Accessing dynamic object in response #14

Open ChrisChinchilla opened 5 years ago

ChrisChinchilla commented 5 years ago

Hey there,

I'm trying to entityLevel setting correct when I have a response that sets it's own internal id as the object, for example, the response:

"list": {
    "2214462582": {
      …
    },
    "2286786905": {
…    
}
  },

etc. So at the moment I have entityLevel:list``, but this results in a GraphQL query of:

{
allTypeposts{
  edges{
  node{
    alternative_2214462582{
      resolved_title
    }
  }
  }
}
}

etc, And I'm not 100% sure if that will cause issues elsewhere in Gatsby? For example, what query do I now use to show a list of all items?

Sorry, bit new to Gatsby, so maybe this is a really dumb question.

thinhle-agilityio commented 5 years ago

@ChrisChinchilla If you want to query list all items, you have to convert your original data from nested object into array. Something like

{list: [item1, item2]}

Other wise, it cannot predict each node name for your query, e.g: alternative_2214462582

ChrisChinchilla commented 5 years ago

Thanks! @thinhle-agilityio I'll give that a go.