butlerx / gatsby-source-google-spreadsheets

A source plugin for Gatsby that allows reading data from Google Sheets.
MIT License
39 stars 10 forks source link

Rows from two worksheets are mixed up when one of them was duplicated from another #29

Closed shoamano83 closed 1 year ago

shoamano83 commented 1 year ago

Describe the bug

I use two instances of this plugin to read out two Google spreadsheets. With Gatsby v4 and later, I noticed that rows from a worksheet are mixed up with rows from another worksheet, when one of the worksheet was duplicated from another.

To Reproduce

Steps to reproduce the behavior:

  1. Create a Google spreadsheet, let's say "SampleSpreadsheet1". It contains a worksheet called "SheetA". Put some data on it. Example

  2. Duplicate the spreadsheet using "File" -> "Make a copy" menu. Name the new spreadsheet as "SampleSpreadsheet2".

  3. Edit the new spreadsheet; modify some data, and rename the worksheet to be "SheetB". Example

  4. Set up a Gatsby project (v4 or later) and configure it to use two instances of this plugin.

  5. Add codes to examine output of GraphQL allGoogleSheetASheet and allGoogleSheetBSheet.

  6. run npm run build and examine the output.

Minimal reproduction: https://github.com/shoamano83/repro-gatsby-source-google-spreadsheets-duplicate-sheets

When I run npm run build, I see following in the log:

Data from SheetA:
[
  { node: { name: 'Carol', age: 42 } },
  { node: { name: 'Dave', age: 16 } },
  { node: { name: 'Ellen', age: 30 } }
]
Data from SheetB:
[
  { node: { name: 'Dave', age: 16 } },
  { node: { name: 'Ellen', age: 30 } }
]

Two rows from SheetB (Dave and Ellen) are pushed to SheetA as well.

Expected behavior

Rows from allGoogleSheetASheet should not mixed up with those from allGoogleSheetBSheet. With the above minimal reproduction, I expect to see something like this in the log:

Data from SheetA:
[
  { node: { name: 'Alice', age: 10 } },
  { node: { name: 'Bob', age: 25 } },
  { node: { name: 'Carol', age: 42 } }
]
Data from SheetB:
[
  { node: { name: 'Dave', age: 16 } },
  { node: { name: 'Ellen', age: 30 } }
]

Additional context

The issue reproduced with Gatsby v4.25.4 and v5.6.1. I did not see the issue with Gatsby v3.

shoamano83 commented 1 year ago

Hello. First of all, thank you for maintaining a useful plugin!

I debugged the issue and created a PR. I know this is really a corner-case issue, but I would appreciate if you could include the patch (and publish a new version!)

Thanks!