Skip to content

Graphql Admin client should not require a session argument #1352

Open
@reed

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

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions