prismic-gatsby icon indicating copy to clipboard operation
prismic-gatsby copied to clipboard

Coordinate Fields are incorrectly defined as Non-nullable

Open TannerJuby1 opened this issue 2 years ago • 2 comments

Versions

  • gatsby-source-prismic: 5.2.2
  • gatsby-plugin-prismic-previews: 5.2.1
  • node: 16.13.2

Steps to reproduce

  • Create a Prismic Custom Type with a Coordinates Field
  • Create a record of this type and don't set Coordinates
  • Create a GraphQL query that queries for the coordinates

What is expected?

I would expect Gatsby to be able to handle null values for all Prismic fields (except UID) given the fact that Prismic does not have a required feature for fields (except UID)

What is actually happening?

I get an error saying The field "PrismicGeoPointType.latitude" was explicitly defined as non-nullable via the schema customization API.

TannerJuby1 avatar Jul 06 '22 16:07 TannerJuby1

I resolved this by adding an infer to my gatsby node:

exports.createSchemaCustomization = ({ actions, schema }) => {
  const { createTypes } = actions
  const { buildObjectType } = schema

  const PrismicGeoPointType = buildObjectType({
    name: 'PrismicGeoPointType',
    fields: {
      latitude: 'Float',
      longitude: 'Float'
    }
  })

  createTypes(PrismicGeoPointType)
}

jodiedoubleday avatar Jul 15 '22 08:07 jodiedoubleday

Thanks @TannerJuby1 and @jodiedoubleday. I will include this fix in the next major version (details are available in an RFC here).

In the meantime, @jodiedoubleday's fix should work.

angeloashmore avatar Jul 18 '22 22:07 angeloashmore