brandonmp / gatsby-source-google-sheets

A GatsbyJS plugin that pulls nodes from rows in a Google Sheet.
90 stars 32 forks source link

Mixed field types #35

Open ettzzi opened 4 years ago

ettzzi commented 4 years ago

Hello, I am trying to receive data from a list of shops. The column "name" contains the names of all shops. I have a name that is called 128 and I think is breaking the plugin:

I receive the following error:

warn There are conflicting field types in your data.

If you have explicitly defined a type for those fields, you can safely ignore this warning message.
Otherwise, Gatsby will omit those fields from the GraphQL schema.

If you know all field types in advance, the best strategy is to explicitly define them with the `createTypes` action, and skip inference with the `@dontInfer` directive.
See https://www.gatsbyjs.org/docs/actions/#createTypes
googleSheetEsercentiRow.name:
 - type: number
   value: 128
 - type: string
   value: 'Clothing Company'
ettzzi commented 4 years ago

Looks like following the advice in the warning message I have solved the issue by defining a custom type.

      type googleSheetEsercentiRow implements Node {
        address: String
        children: NodeFilterListInput
        id: String
        name: String
        phone1: String,
        phone2: String
        internal: InternalFilterInput
        neighborhood: String
        parent: NodeFilterInput
        type: String          
      }

Is this the best solution?

brybeecher commented 4 years ago

Worked for me. In my gatsby-node.js:

exports.createSchemaCustomization = ({ actions }) => {
  const { createTypes } = actions
  const typeDefs = `
    type googleSheetWebsiteDataSourceRow implements Node @dontInfer {
      zip: String!
      businessname: String!
    }
  `
  createTypes(typeDefs)
}