A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
So in the documents for the ruby gem shopify_api there is some framework code at:
https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/session_storage.md
There is a skeleton initialize method, but what do I need to do in order to create a new instance of this class? [I am unfamiliar with the post 9.5.1 Rest libraries]
class CustomSessionStorage
include ShopifyAPI::Auth::SessionStorage
def initialize
# Initialize as needed
end
def store_session(session)
# Implement a store function
some_store_function(id: session.id, session_data: session.serialize)
end
def load_session(id)
# Implement a fetch function
session_data = some_fetch_function(id)
ShopifyAPI::Auth::Session.deserialize(session_data)
end
def delete_session(id)
# Implement a delete function
some_delete_function(id)
true
end
end
What sort of type for the session_data do I need in Postgresql? JSON? Something else?that
Is there some sort of table set up migration someone can share with me?
Obviously I don't want in production to use the FileSessionStorage as in below:
ShopifyAPI::Context.setup(
api_key: "DUMMY",
api_secret_key: @Dev_app_token,
scope: "DUMMY",
host_name: "DUMMY",
private_shop: "#{@dev_shopname}.myshopify.com",
session_storage: ShopifyAPI::Auth::FileSessionStorage.new,
is_embedded: false,
is_private: true,
api_version: "2022-07"
)
This is for a private app, that might end up eventually as an AWS Lambda function, specifically to bulk update inventory using GraphQL, but I do need the Rest API as well for somethings as well. Thus I cannot use the Rails shopify_app gem but the shopify_api gem.
Any help, pointers on the Postgresql set up (particularly if I can use ActiveRecord, want to keep using Sinatra/Activerecord for migrations, etc.) would be appreciated as well as possibly notes/explanation of what I need to do in the skeleton methods for a production system.
Many thanks!
Hi, Michael here. Building with ruby on rails shopify app. Did you find any answer to your question?
I'm facing the issue as well. I'm not really sure to understand the flow for the gem and the session storage.
I'm saving the access_token after the oath process, but then when I do
ShopifyAPI::Auth::Session.new(shop: shopify_domain, access_token: access_token)
After a few hours (maybe 24?) i get ShopifyAPI::Errors::HttpResponseError ([API] Invalid API key or access token (unrecognized login or wrong password)
Not sure, i'm probably missing something.
Let me know if you found any solution 🙂
Michael
Hi Mike --
Never did get an answer. The newer version of the gem does not require SessionStorage so I just leave it off. Have to upgrade my existing Legacy Rails App and that will be fun. If I find a solution I will leave it here.