Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #632 from mirumee/feature/improve_queries_on_landi…
Browse files Browse the repository at this point in the history
…ng_page

Use sdk for fetching shop details
  • Loading branch information
mateuszkula authored Feb 28, 2020
2 parents 71ebdfb + 31bc789 commit b4a7856
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/@sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export class SaleorAPI {
data => data.productVariants
);

getShopDetails = this.watchQuery(QUERIES.GetShopDetails, data => data);

setUserDefaultAddress = this.fireQuery(
MUTATIONS.AddressTypeUpdate,
data => data!.accountSetDefaultAddress
Expand Down
13 changes: 13 additions & 0 deletions src/@sdk/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as Category from "./category";
import * as Checkout from "./checkout";
import * as Orders from "./orders";
import * as Product from "./products";
import * as Shop from "./shop";
import * as WishlistQuery from "./wishlist";

import {
Expand All @@ -32,6 +33,8 @@ import {
CategoryDetailsVariables,
} from "./types/CategoryDetails";

import { GetShop } from "./types/GetShop";

import { OrdersByUser, OrdersByUserVariables } from "./types/OrdersByUser";
import { UserCheckoutDetails } from "./types/UserCheckoutDetails";
import { UserDetails } from "./types/UserDetails";
Expand Down Expand Up @@ -79,6 +82,16 @@ export const QUERIES = {
`,
...options,
}),
GetShopDetails: <TCacheShape>(
client: ApolloClient<TCacheShape>,
options: QueryOptions<null>
): ObservableQuery<GetShop, any> =>
client.watchQuery({
query: gql`
${Shop.getShop}
`,
...options,
}),
OrderDetails: <TCacheShape>(
client: ApolloClient<TCacheShape>,
options: QueryOptions<OrderByTokenVariables>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import gql from "graphql-tag";

import { TypedQuery } from "../../core/queries";
import { getShop } from "./types/getShop";

const getShopQuery = gql`
query getShop {
export const getShop = gql`
query GetShop {
shop {
displayGrossPrices
defaultCountry {
Expand All @@ -24,5 +21,3 @@ const getShopQuery = gql`
}
}
`;

export const TypedGetShopQuery = TypedQuery<getShop, {}>(getShopQuery);
78 changes: 78 additions & 0 deletions src/@sdk/queries/types/GetShop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* tslint:disable */
/* eslint-disable */
// This file was automatically generated and should not be edited.

// ====================================================
// GraphQL query operation: GetShop
// ====================================================

export interface GetShop_shop_defaultCountry {
__typename: "CountryDisplay";
/**
* Country code.
*/
code: string;
/**
* Country name.
*/
country: string;
}

export interface GetShop_shop_countries {
__typename: "CountryDisplay";
/**
* Country name.
*/
country: string;
/**
* Country code.
*/
code: string;
}

export interface GetShop_shop_geolocalization_country {
__typename: "CountryDisplay";
/**
* Country code.
*/
code: string;
/**
* Country name.
*/
country: string;
}

export interface GetShop_shop_geolocalization {
__typename: "Geolocalization";
/**
* Country of the user acquired by his IP address.
*/
country: GetShop_shop_geolocalization_country | null;
}

export interface GetShop_shop {
__typename: "Shop";
/**
* Display prices with tax in store.
*/
displayGrossPrices: boolean;
/**
* Shop's default country.
*/
defaultCountry: GetShop_shop_defaultCountry | null;
/**
* List of countries available in the shop.
*/
countries: (GetShop_shop_countries | null)[];
/**
* Customer's geolocalization data.
*/
geolocalization: GetShop_shop_geolocalization | null;
}

export interface GetShop {
/**
* Return information about the shop.
*/
shop: GetShop_shop | null;
}
2 changes: 2 additions & 0 deletions src/@sdk/react/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { queryFactory, queryWithVariablesFactory } from "./useQuery";
export const useProductDetails = queryWithVariablesFactory("getProductDetails");
export const useProductList = queryWithVariablesFactory("getProductList");

export const useShopDetails = queryFactory("getShopDetails");

export const useUserDetails = queryFactory("getUserDetails");

export const useUserCheckout = queryFactory("getUserCheckout");
Expand Down
20 changes: 10 additions & 10 deletions src/components/ShopProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import * as React from "react";

import { maybe } from "../../core/utils";
import { defaultContext, ShopContext } from "./context";
import { TypedGetShopQuery } from "./queries";

const ShopProvider: React.FC = ({ children }) => (
<TypedGetShopQuery displayLoader={false} displayError={false}>
{({ data }) => (
<ShopContext.Provider value={maybe(() => data.shop, defaultContext)}>
{children}
</ShopContext.Provider>
)}
</TypedGetShopQuery>
);
import { useShopDetails } from "@sdk/react";

const ShopProvider: React.FC = ({ children }) => {
const { data } = useShopDetails();
return (
<ShopContext.Provider value={maybe(() => data.shop, defaultContext)}>
{children}
</ShopContext.Provider>
);
};

export default ShopProvider;

0 comments on commit b4a7856

Please sign in to comment.