Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Gatsby custom resolvers error in v2.5.0+ #128

Closed
tbrannam opened this issue Oct 10, 2020 · 1 comment
Closed

[BUG] Gatsby custom resolvers error in v2.5.0+ #128

tbrannam opened this issue Oct 10, 2020 · 1 comment

Comments

@tbrannam
Copy link
Contributor

Some custom resolvers that we have implemented fail when using gatsby-source-datocms version 2.5.0+.

The shape of the first argument of the resolver (shown in gatsby-node.js in the examples) receives different shapes of data between these versions.

resolve: async (item, { siteId, currency }, context)

Note that the CMS Model fields in nested into entityPayload.attributes instead of being at the root in prior versions

catalogItem {
  id: 'DatoCmsCatalogItem-xxxx-en-US',
  parent: null,
  children: [],
  internal: {
    type: 'DatoCmsCatalogItem',
    contentDigest: '2020-08-07T20:48:29.942+01:00',
    counter: 155,
    owner: 'gatsby-source-datocms'
  },
  locale: 'en-US',
  entityPayload: {
    id: '5808923',
    type: 'item',
    attributes: {
      product_id: 1,
      sku: 'xxxxx',
      product: '5808943',
      site_id: 'xxxx',
      gatsbypreview: null,
      updated_at: '2020-08-07T20:48:29.942+01:00',
      created_at: '2020-08-07T17:26:05.010+01:00'
    },
    relationships: { item_type: [Object], creator: [Object] },
    meta: {
      created_at: '2020-08-07T17:26:05.010+01:00',
      updated_at: '2020-08-07T20:48:29.942+01:00',
      published_at: '2020-08-07T20:48:29.962+01:00',
      publication_scheduled_at: null,
      first_published_at: '2020-08-07T17:26:05.020+01:00',
      is_valid: true,
      status: 'published',
      current_version: '10677674'
    }
  },
  seoMetaTags___NODE: 'DatoCmsSeoMetaTags-DatoCmsCatalogItem-5808923-en-US',
  __gatsby_resolved: { product: {}, siteId: 'xxxx', locale: 'en-US' }
}

I've isolated the code into these two sandboxes. They require an update gatsby-config.js with a Dato apiKey.

https://codesandbox.io/s/dato-source-graphql-v241-public-p35io?file=/README.md

https://codesandbox.io/s/dato-source-graphql-v250-public-z4wfs?file=/README.md

Using one of my Dato environments I can make this query using 2.4.1, but fails on 2.5.0 and newer

query MyQuery {
  datoCmsProductPage {
    defaultCatalogItem {
      price(currency: USD, siteId: "flamingo_us") {
        value
        currency
      }
    }
  }
}
@tbrannam tbrannam changed the title Gatsby custom resolvers error in v2.5.0+ [BUG] Gatsby custom resolvers error in v2.5.0+ Oct 10, 2020
@stefanoverna
Copy link
Member

Yes, in recent versions, to achieve better loading performance, we had to make changes to how we store information inside the nodes, so yeah, the correct way now to read information is using source.entityPayload which returns exactly the JSON API response of our CMA with no transformations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants