Description
The documentation at custom_apps.md indicates that you do not need to pass in a session argument when initializing a ShopifyAPI::Clients::Graphql::Admin
client because it will use the active session (if it exists):
![Image](https://private-user-images.githubusercontent.com/672142/397462232-212e39b3-e64f-412a-b7b6-ce8ab5fbfb7c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5Mjg4MTMsIm5iZiI6MTczODkyODUxMywicGF0aCI6Ii82NzIxNDIvMzk3NDYyMjMyLTIxMmUzOWIzLWU2NGYtNDEyYS1iN2I2LWNlOGFiNWZiZmI3Yy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwN1QxMTQxNTNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0zMjA0N2Q1ZDU2OGU2MzBhZmU4ZTI0MGUzZDAzMjliNjMzYWU3ZmNlMjkxODJjZWMyMTQyMDA1YWU4YjUxZTMzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.EywILKH9YMTxeuqhgfz9FFLlffTc93F_kB1PVqTRU80)
However, this example would raise an exception because the session
argument is required:
# lib/shopify_api/clients/graphql/admin.rb
module ShopifyAPI
module Clients
module Graphql
class Admin < Client
sig { params(session: T.nilable(Auth::Session), api_version: T.nilable(String)).void }
def initialize(session:, api_version: nil) # session argument does not have a default value
super(session: session, base_path: "/admin/api", api_version: api_version)
end
end
end
end
end
Therefore if you want to use the active session, you have to pass in session: nil
:
graphql_client = ShopifyAPI::Clients::Graphql::Admin.new(session: nil, api_version: "2024-07")
This seems counter-intuitive to me, as it makes it look like the code is deliberately saying it doesn't want to use a session. I think that what is shown in the documentation is how it should work, that you can omit the argument in order to use the active session. The REST Admin Client behaves this way, so I think it only makes sense that the Graphql Admin Client does too.
I can submit a PR to make this change if you'd like. Or if you disagree and want to keep the existing behavior, then I can submit a PR to fix the documentation.