January 28, 2022
Using GraphQL to interact with Google Sheets using BaseQL
Comments
(0)
January 28, 2022
Using GraphQL to interact with Google Sheets using BaseQL
ColdFusion developer for 20+ years, professional experience in 10 other languages & frameworks. Artist, nerd, Jeep enthusiast.
Newbie 35 posts
Followers: 26 people
(0)

Last time I posted, I added a write functionality to my already existing talks on reading from Airtable APIs using GraphQL by integrating with the BaseQL plugin. There’s been some cool updates there and I wanted to share them, as they potentially open up an amazing and exciting new arena for using ColdFusion to write sites that leverage low-code/no-code sources for data.

One big piece of news coming from BaseQL is that you no longer need to have a pro Airtable account to use it. That’s a huge improvement, as the costs for the pro Airtable accounts quickly add up with even smaller teams.

The bigger news (in my opinion anyhow) is the addition of Google Sheets as a datasource. This feature is currently in BETA, so of course use with proper caution (and obviously don’t toss it into production yet). I’m going to go over how you can leverage it in this article, and then I will be doing a live coding session on Wednesday, February 2nd at 1pm on Twitch (https://twitch.tv/MarkTakata) to show you how to do it, so be sure to swing by.

OK, so to start, make sure you have a BaseQL account. They are free and you can get one at baseql.com. Sign in.

Then you can select “Add New Data Source”.  You’ll be asked to paste in a URL. To generate this URL, click the “share” button in your Google Sheet, select the option to allow anyone with the link to access the info, and change the permissions to “editor”. Copy the URL.

Back at the BaseQL site, paste that URL and delete everything past the word “edit”. Save it. You’ll be asked to authenticate and add additional permissions to that sheet. Click OK.

Now you’ll be sent to the BaseQL dashboard, which you should already be familiar with. In the left pane you can select the fields you want to interact with, whether you’re generating a query or a mutation, etc. From here you can play with the data by selecting fields and hitting play to return data.

A few things to note:

  • The ID field returned is NULL for me. I’m not certain if this is a bug or not, but for the moment we are not seeing any kind of generated ID field, so when building your columns in Google Sheets, you might consider some form of unique ID field, especially if you plan to use this for mutations. As a reminder, you can set a column to autonumber by adding the formula =ROW() to it. This is of course not the same as setting the column type to autonumber, but can provide you with at least some kind of orderable ID. Keep in mind, this is a spreadsheet not a DB (or even a psuedo-db like Airtable) so you’ll be missing a few features you might be used to.
  • The link ID might be NULL at first. After playing around with some of the columns and buttons it finally refreshed and showed a proper link to link your CFHTTP request to.

As far as the code is concerned, something along these lines will return the information you want:

<cfset graphqlqueryvalue = '{"query": "{sheet1 { id age name sex }}"}' />
<cfhttp  url="https://api.baseql.com/airtable/graphql/INSERT-UNIQUE-CODE-HERE" method="post" result="graphql">
<cfhttpparam  type="header" name="Content-Type" value="application/json">
<cfhttpparam  type="header" name="Accept" value="application/json">
<cfhttpparam  type="body" value="#graphqlqueryvalue#">
Then you simply output the value from the call. We’ll save mutations for next week’s Twitch stream. Enjoy!

UPDATE: I’ve been informed that the Google Sheets beta currently does not support mutations, so we’ll be focusing on just pulling and displaying data during my stream tomorrow.

0 Comments
Add Comment