pub struct ShopifyClient { /* private fields */ }Expand description
An Admin GraphQL client for one shop and one token.
A clone is cheap. Debug redacts the token.
Implementations§
Source§impl ShopifyClient
impl ShopifyClient
Sourcepub fn new(
shop: ShopDomain,
api_version: ApiVersion,
access_token: impl Into<String>,
) -> Result<Self>
pub fn new( shop: ShopDomain, api_version: ApiVersion, access_token: impl Into<String>, ) -> Result<Self>
Make a client for shop with a new HTTP connection pool.
§Errors
Returns Error::Config when the token is blank, or
Error::Http when the HTTP client does not build.
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> Self
pub fn with_base_url(self, base_url: impl Into<String>) -> Self
Send requests to base_url instead of https://{shop}. Use it for
a local stub in tests. The requests carry the access token, so use
only a host you trust.
Sourcepub const fn with_retry(self, retry: RetryPolicy) -> Self
pub const fn with_retry(self, retry: RetryPolicy) -> Self
Set the retry policy.
Sourcepub const fn shop(&self) -> &ShopDomain
pub const fn shop(&self) -> &ShopDomain
The shop this client calls.
Sourcepub const fn api_version(&self) -> &ApiVersion
pub const fn api_version(&self) -> &ApiVersion
The API version this client uses.
Sourcepub async fn graphql(&self, query: &str, variables: Value) -> Result<Value>
pub async fn graphql(&self, query: &str, variables: Value) -> Result<Value>
Run a GraphQL document and return its data.
§Errors
Returns Error::Http on a transport failure,
Error::ShopifyApi on a non-success status, Error::GraphQl
when the response has errors, Error::UnexpectedResponse when the
body has no data, and Error::Throttled when the retries run
out.
Sourcepub async fn query<T: DeserializeOwned>(
&self,
query: &str,
variables: Value,
) -> Result<T>
pub async fn query<T: DeserializeOwned>( &self, query: &str, variables: Value, ) -> Result<T>
Run a GraphQL document and deserialize its data into T.
§Errors
See graphql. Also returns
Error::UnexpectedResponse when data does not match T.
Sourcepub async fn subscribe_webhook(
&self,
topic: &str,
callback_url: &str,
) -> Result<String>
pub async fn subscribe_webhook( &self, topic: &str, callback_url: &str, ) -> Result<String>
Subscribe callback_url to topic (for example orders/create)
with webhookSubscriptionCreate. Returns the subscription id.
The compliance topics are not in the GraphQL topic enum. Declare
them in shopify.app.toml (compliance_topics).
§Errors
Returns Error::InvalidRequest for a malformed topic and
Error::Config for a compliance topic. See also
query. Returns Error::GraphQl with the
userErrors messages when Shopify refuses the subscription.
Trait Implementations§
Source§impl Clone for ShopifyClient
impl Clone for ShopifyClient
Auto Trait Implementations§
impl !RefUnwindSafe for ShopifyClient
impl !UnwindSafe for ShopifyClient
impl Forget for ShopifyClient
impl Freeze for ShopifyClient
impl Send for ShopifyClient
impl Sync for ShopifyClient
impl Unpin for ShopifyClient
impl UnsafeUnpin for ShopifyClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Scoped for T
impl<T> Scoped for T
Source§fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
ScopeQuery for this type. Resolves the
registered scope at .load() time, not here.