Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Ensure that all queries are built on top of TypedQuery
dominik-zeglen29804f87d98f
diff --git a/saleor/static/dashboard-next/pages/queries.ts b/saleor/static/dashboard-next/pages/queries.tsindex cc20216ab0..a9da0995f9 100644--- a/saleor/static/dashboard-next/pages/queries.ts+++ b/saleor/static/dashboard-next/pages/queries.ts@@ -1,13 +1,10 @@import gql from "graphql-tag";-import { Query, QueryProps } from "react-apollo";+import { TypedQuery } from "../queries";import { PageDetails, PageDetailsVariables } from "./types/PageDetails";import { PageList, PageListVariables } from "./types/PageList";-export const TypedPageListQuery = Query as React.ComponentType<- QueryProps<PageList, PageListVariables>->;-export const pageListQuery = gql`+const pageListQuery = gql`query PageList($first: Int, $after: String, $last: Int, $before: String) {pages(before: $before, after: $after, first: $first, last: $last) {edges {@@ -28,11 +25,11 @@ export const pageListQuery = gql`}}`;+export const TypedPageListQuery = TypedQuery<PageList, PageListVariables>(+ pageListQuery+);-export const TypedPageDetailsQuery = Query as React.ComponentType<- QueryProps<PageDetails, PageDetailsVariables>->;-export const pageDetailsQuery = gql`+const pageDetailsQuery = gql`query PageDetails($id: ID!) {page(id: $id) {id@@ -45,3 +42,7 @@ export const pageDetailsQuery = gql`}}`;+export const TypedPageDetailsQuery = TypedQuery<+ PageDetails,+ PageDetailsVariables+>(pageDetailsQuery);diff --git a/saleor/static/dashboard-next/pages/views/PageDetails.tsx b/saleor/static/dashboard-next/pages/views/PageDetails.tsxindex 4d0de0df2c..c3ce1523fb 100644--- a/saleor/static/dashboard-next/pages/views/PageDetails.tsx+++ b/saleor/static/dashboard-next/pages/views/PageDetails.tsx@@ -8,7 +8,7 @@ import i18n from "../../i18n";import { maybe } from "../../misc";import PageDetailsPage from "../components/PageDetailsPage";import { TypedPageDeleteMutation, TypedPageUpdateMutation } from "../mutations";-import { pageDetailsQuery, TypedPageDetailsQuery } from "../queries";+import { TypedPageDetailsQuery } from "../queries";import { pageListUrl } from "../urls";interface PageUpdateFormProps {@@ -32,7 +32,7 @@ export class PageUpdateForm extends React.Component<render() {const { id } = this.props;return (- <TypedPageDetailsQuery query={pageDetailsQuery} variables={{ id }}>+ <TypedPageDetailsQuery variables={{ id }}>{({ data: detailsResult, error, loading }) => {if (error) {return (diff --git a/saleor/static/dashboard-next/pages/views/PageList.tsx b/saleor/static/dashboard-next/pages/views/PageList.tsxindex 3dbf53146e..a8ad759586 100644--- a/saleor/static/dashboard-next/pages/views/PageList.tsx+++ b/saleor/static/dashboard-next/pages/views/PageList.tsx@@ -6,7 +6,7 @@ import { createPaginationState, Paginator } from "../../components/Paginator";import i18n from "../../i18n";import { maybe } from "../../misc";import PageListPage from "../components/PageListPage/PageListPage";-import { pageListQuery, TypedPageListQuery } from "../queries";+import { TypedPageListQuery } from "../queries";import { pageAddUrl, pageUrl } from "../urls";export type PageListQueryParams = Partial<{ after: string; before: string }>;@@ -25,11 +25,7 @@ export const PageList: React.StatelessComponent<PageListProps> = ({const paginationState = createPaginationState(PAGINATE_BY, params);const handleEditClick = (id: string) => () => navigate(pageUrl(id));return (- <TypedPageListQuery- query={pageListQuery}- variables={paginationState}- fetchPolicy="network-only"- >+ <TypedPageListQuery variables={paginationState}>{({ data, loading, error }) => {if (error) {return (diff --git a/saleor/static/dashboard-next/products/queries.ts b/saleor/static/dashboard-next/products/queries.tsindex 3b56a32f53..205f17c9e8 100644--- a/saleor/static/dashboard-next/products/queries.ts+++ b/saleor/static/dashboard-next/products/queries.ts@@ -1,6 +1,6 @@import gql from "graphql-tag";-import { Query, QueryProps } from "react-apollo";+import { TypedQuery } from "../queries";import { ProductCreateData } from "./types/ProductCreateData";import {ProductDetails,@@ -208,11 +208,7 @@ export const fragmentVariant = gql`}`;-export const TypedProductListQuery = Query as React.ComponentType<- QueryProps<ProductList, ProductListVariables>->;--export const productListQuery = gql`+const productListQuery = gql`${fragmentMoney}query ProductList($first: Int@@ -254,12 +250,12 @@ export const productListQuery = gql`}}`;+export const TypedProductListQuery = TypedQuery<+ ProductList,+ ProductListVariables+>(productListQuery);-export const TypedProductDetailsQuery = Query as React.ComponentType<- QueryProps<ProductDetails, ProductDetailsVariables>->;--export const productDetailsQuery = gql`+const productDetailsQuery = gql`${fragmentProduct}query ProductDetails($id: ID!) {product(id: $id) {@@ -283,12 +279,12 @@ export const productDetailsQuery = gql`}}`;+export const TypedProductDetailsQuery = TypedQuery<+ ProductDetails,+ ProductDetailsVariables+>(productDetailsQuery);-export const TypedProductVariantQuery = Query as React.ComponentType<- QueryProps<ProductVariantDetails, ProductVariantDetailsVariables>->;--export const productVariantQuery = gql`+const productVariantQuery = gql`${fragmentVariant}query ProductVariantDetails($id: ID!) {productVariant(id: $id) {@@ -296,11 +292,12 @@ export const productVariantQuery = gql`}}`;+export const TypedProductVariantQuery = TypedQuery<+ ProductVariantDetails,+ ProductVariantDetailsVariables+>(productVariantQuery);-export const TypedProductCreateQuery = Query as React.ComponentType<- QueryProps<ProductCreateData>->;-export const productCreateQuery = gql`+const productCreateQuery = gql`query ProductCreateData {productTypes {edges {@@ -340,11 +337,11 @@ export const productCreateQuery = gql`}}`;+export const TypedProductCreateQuery = TypedQuery<ProductCreateData, {}>(+ productCreateQuery+);-export const TypedProductVariantCreateQuery = Query as React.ComponentType<- QueryProps<ProductVariantCreateData, ProductVariantCreateDataVariables>->;-export const productVariantCreateQuery = gql`+const productVariantCreateQuery = gql`query ProductVariantCreateData($id: ID!) {product(id: $id) {id@@ -391,11 +388,12 @@ export const productVariantCreateQuery = gql`}}`;+export const TypedProductVariantCreateQuery = TypedQuery<+ ProductVariantCreateData,+ ProductVariantCreateDataVariables+>(productVariantCreateQuery);-export const TypedProductImageQuery = Query as React.ComponentType<- QueryProps<ProductImageById, ProductImageByIdVariables>->;-export const productImageQuery = gql`+const productImageQuery = gql`query ProductImageById($productId: ID!, $imageId: ID!) {product(id: $productId) {id@@ -421,3 +419,7 @@ export const productImageQuery = gql`}}`;+export const TypedProductImageQuery = TypedQuery<+ ProductImageById,+ ProductImageByIdVariables+>(productImageQuery);diff --git a/saleor/static/dashboard-next/products/views/ProductCreate.tsx b/saleor/static/dashboard-next/products/views/ProductCreate.tsxindex 746c40db3e..a199980dfb 100644--- a/saleor/static/dashboard-next/products/views/ProductCreate.tsx+++ b/saleor/static/dashboard-next/products/views/ProductCreate.tsx@@ -9,7 +9,7 @@ import i18n from "../../i18n";import { decimal, maybe } from "../../misc";import ProductCreatePage from "../components/ProductCreatePage";import { TypedProductCreateMutation } from "../mutations";-import { productCreateQuery, TypedProductCreateQuery } from "../queries";+import { TypedProductCreateQuery } from "../queries";import { ProductCreate } from "../types/ProductCreate";import { productListUrl, productUrl } from "../urls";@@ -31,7 +31,7 @@ export const ProductUpdate: React.StatelessComponent<const handleBack = () => navigate(productListUrl());return (- <TypedProductCreateQuery query={productCreateQuery}>+ <TypedProductCreateQuery>{({ data, error, loading }) => {const handleSuccess = (data: ProductCreate) => {if (data.productCreate.errors.length === 0) {diff --git a/saleor/static/dashboard-next/products/views/ProductImage/index.tsx b/saleor/static/dashboard-next/products/views/ProductImage/index.tsxindex 3cb6ecd9c0..c3659c892a 100644--- a/saleor/static/dashboard-next/products/views/ProductImage/index.tsx+++ b/saleor/static/dashboard-next/products/views/ProductImage/index.tsx@@ -11,7 +11,7 @@ import {TypedProductImageDeleteMutation,TypedProductImageUpdateMutation} from "../../mutations";-import { productImageQuery, TypedProductImageQuery } from "../../queries";+import { TypedProductImageQuery } from "../../queries";import { ProductImageUpdate } from "../../types/ProductImageUpdate";import { productImageUrl, productUrl } from "../../urls";import { productImageRemoveUrl } from "./urls";@@ -41,12 +41,10 @@ export const ProductImage: React.StatelessComponent<ProductImageProps> = ({};return (<TypedProductImageQuery- query={productImageQuery}variables={{imageId,productId}}- fetchPolicy="cache-and-network">{({ data, loading }) => {return (diff --git a/saleor/static/dashboard-next/products/views/ProductList.tsx b/saleor/static/dashboard-next/products/views/ProductList.tsxindex ee8a75778f..248e80b878 100644--- a/saleor/static/dashboard-next/products/views/ProductList.tsx+++ b/saleor/static/dashboard-next/products/views/ProductList.tsx@@ -8,7 +8,7 @@ import { maybe } from "../../misc";import { StockAvailability } from "../../types/globalTypes";import ProductListCard from "../components/ProductListCard";import { getTabName } from "../misc";-import { productListQuery, TypedProductListQuery } from "../queries";+import { TypedProductListQuery } from "../queries";import { productAddUrl, productUrl } from "../urls";export interface ProductListFilters {@@ -43,12 +43,10 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({const paginationState = createPaginationState(PAGINATE_BY, params);return (<TypedProductListQuery- query={productListQuery}variables={{...paginationState,stockAvailability: params.status}}- fetchPolicy="network-only">{({ data, loading, error }) => {if (error) {diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsxindex 8e6a5e41c0..1965e14ad8 100644--- a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx+++ b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx@@ -14,7 +14,7 @@ import { decimal, maybe } from "../../../misc";import { productTypeUrl } from "../../../productTypes/urls";import ProductUpdatePage from "../../components/ProductUpdatePage";import ProductUpdateOperations from "../../containers/ProductUpdateOperations";-import { productDetailsQuery, TypedProductDetailsQuery } from "../../queries";+import { TypedProductDetailsQuery } from "../../queries";import {productImageUrl,productListUrl,@@ -37,11 +37,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({<Navigator>{navigate => {return (- <TypedProductDetailsQuery- query={productDetailsQuery}- variables={{ id }}- fetchPolicy="network-only"- >+ <TypedProductDetailsQuery variables={{ id }}>{({ data, loading, error }) => {if (error) {return <ErrorMessageCard message="Something went wrong" />;diff --git a/saleor/static/dashboard-next/products/views/ProductVariant/index.tsx b/saleor/static/dashboard-next/products/views/ProductVariant/index.tsxindex 231332ad77..3c4f8feeba 100644--- a/saleor/static/dashboard-next/products/views/ProductVariant/index.tsx+++ b/saleor/static/dashboard-next/products/views/ProductVariant/index.tsx@@ -11,7 +11,7 @@ import { decimal, maybe } from "../../../misc";import ProductVariantDeleteDialog from "../../components/ProductVariantDeleteDialog";import ProductVariantPage from "../../components/ProductVariantPage";import ProductVariantOperations from "../../containers/ProductVariantOperations";-import { productVariantQuery, TypedProductVariantQuery } from "../../queries";+import { TypedProductVariantQuery } from "../../queries";import { VariantUpdate } from "../../types/VariantUpdate";import { productUrl, productVariantEditUrl } from "../../urls";import { productVariantRemoveUrl } from "./urls";@@ -41,11 +41,7 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({{navigate => (<Messages>{pushMessage => (- <TypedProductVariantQuery- query={productVariantQuery}- variables={{ id: variantId }}- fetchPolicy="network-only"- >+ <TypedProductVariantQuery variables={{ id: variantId }}>{({ data, loading, error }) => {if (error) {return <ErrorMessageCard message="Something went wrong" />;diff --git a/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx b/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsxindex 4ffd3f2da4..16dc1fa54b 100644--- a/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx+++ b/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx@@ -9,10 +9,7 @@ import i18n from "../../i18n";import { decimal, maybe } from "../../misc";import ProductVariantCreatePage from "../components/ProductVariantCreatePage";import { TypedVariantCreateMutation } from "../mutations";-import {- productVariantCreateQuery,- TypedProductVariantCreateQuery-} from "../queries";+import { TypedProductVariantCreateQuery } from "../queries";import { VariantCreate } from "../types/VariantCreate";import { productUrl, productVariantEditUrl } from "../urls";@@ -40,10 +37,7 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({{navigate => (<Messages>{pushMessage => (- <TypedProductVariantCreateQuery- query={productVariantCreateQuery}- variables={{ id: productId }}- >+ <TypedProductVariantCreateQuery variables={{ id: productId }}>{({ data, error, loading: productLoading }) => {if (error) {return (