30 releases (7 breaking)

0.9.0 Jul 10, 2024
0.8.9 May 30, 2024
0.6.0 Mar 8, 2024
0.4.8 Sep 4, 2023
0.3.4 Oct 18, 2022

#371 in Web programming

Download history 37/week @ 2024-03-31 1/week @ 2024-04-07 146/week @ 2024-04-14 511/week @ 2024-04-21 360/week @ 2024-04-28 10/week @ 2024-05-05 453/week @ 2024-05-12 192/week @ 2024-05-19 187/week @ 2024-05-26 33/week @ 2024-06-02 48/week @ 2024-06-09 140/week @ 2024-06-16 34/week @ 2024-06-23 8/week @ 2024-06-30 119/week @ 2024-07-07 16/week @ 2024-07-14

199 downloads per month

MIT license

495KB
1.5K SLoC

shopify_api

crates.io Documentation MIT/Apache-2 licensed CI Issues

An ergonomic, Shopify API Client for Rust.

  • GraphQL API support with automatic data deserialization
  • Changelog

Example

This asynchronous example uses Tokio and enables some optional features, so your Cargo.toml could look like this:

[dependencies]
shopify_api = "0.8"
tokio = { version = "1", features = ["full"] }

And then the code:

use shopify_api::*;
use shopify_api::utils::ReadJsonTreeSteps;
use serde::{Deserialize};

#[derive(Deserialize)]
struct Shop {
  name: String,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
  let shopify = Shopify::new("hello", "world", String::from("2024-04"), None);

  let graphql_query = r#"
    query {
      shop {
      name
     }
  }"#;

  let variables = serde_json::json!({});
  let json_finder = vec![ReadJsonTreeSteps::Key("data"), ReadJsonTreeSteps::Key("shop")];

  let shop: Shop = shopify.graphql_query(graphql_query, &variables, &json_finder).await.unwrap();
  Ok(())
}

Or with the new GraphQl Client!

[dependencies]
shopify_api = "0.89"
tokio = { version = "1", features = ["full"] }
graphql_client = "0.14.0"
query GetShop {
  shop {
    name
  }
}
use shopify_api::*;
use graphql_client::GraphQLQuery;

#[derive(GraphQLQuery)]
#[graphql(
    schema_path = "./graphql.schema.json",
    query_path = "graphql/getShop.graphql",
    response_derives = "Debug"
)]
struct GetShop;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
  let shopify = Shopify::new("hello", "world", String::from("2024-04"), None);

  let shop_info = connector
        .shopify
        .post_graphql::<GetShop>(get_shop::Variables {})
        .await;

  Ok(())
}

Download the graphql schema

You can download one from this repository

Or download it from the Shopify Graphql API with the following command

[!WARNING] Sometimes you'll get an error with the GraphQLQuery derive caused my a missing struct, most of the time, you can fix it by adding the missing struct by importing it from the types import or you can create a new struct with the same name as the missing one, and the derive will work.

License

Licensed under MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

Dependencies

~7–19MB
~281K SLoC