Skip to content

Commit

Permalink
[PWA-595] GraphQL Build Warning (magento#2421)
Browse files Browse the repository at this point in the history
* Rename checkout fragments and restructure Cart operations

* Rename cart fragments

Co-authored-by: Devagouda <[email protected]>
  • Loading branch information
tjwiebell and dpatil-magento committed May 26, 2020
1 parent ec0b9ca commit e69419d
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import Region from '../../../Region';
import TextInput from '../../../TextInput';
import { CartPageFragment } from '../../cartPageFragments.gql';
import defaultClasses from './shippingForm.css';
import { GET_SHIPPING_METHODS } from './shippingMethods';
import { ShippingMethodsFragment } from './shippingMethodsFragments';
import { GET_SHIPPING_METHODS } from './shippingMethods.gql';
import { ShippingMethodsCartFragment } from './shippingMethodsFragments.gql';

const ShippingForm = props => {
const { hasMethods, selectedShippingFields, setIsCartUpdating } = props;
Expand Down Expand Up @@ -99,12 +99,12 @@ export const SET_SHIPPING_ADDRESS_MUTATION = gql`
cart {
id
...CartPageFragment
...ShippingMethodsFragment
...ShippingMethodsCartFragment
...ShippingInformationFragment
}
}
}
${CartPageFragment}
${ShippingMethodsFragment}
${ShippingMethodsCartFragment}
${ShippingInformationFragment}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import gql from 'graphql-tag';

import { ShippingMethodsCartFragment } from './shippingMethodsFragments.gql';

export const GET_SHIPPING_METHODS = gql`
query GetShippingMethods($cartId: String!) {
cart(cart_id: $cartId) @connection(key: "Cart") {
id
...ShippingMethodsCartFragment
}
}
${ShippingMethodsCartFragment}
`;

export default {
mutations: {},
queries: {
getShippingMethodsQuery: GET_SHIPPING_METHODS
}
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { Fragment } from 'react';
import gql from 'graphql-tag';
import { Form } from 'informed';
import { useShippingMethods } from '@magento/peregrine/lib/talons/CartPage/PriceAdjustments/ShippingMethods/useShippingMethods';

import { mergeClasses } from '../../../../classify';
import Button from '../../../Button';
import ShippingForm from './shippingForm';
import defaultClasses from './shippingMethods.css';
import { ShippingMethodsFragment } from './shippingMethodsFragments';
import ShippingMethodsOperations from './shippingMethods.gql';
import ShippingRadios from './shippingRadios';

const ShippingMethods = props => {
Expand All @@ -19,11 +18,7 @@ const ShippingMethods = props => {
selectedShippingMethod,
shippingMethods,
showForm
} = useShippingMethods({
queries: {
getShippingMethodsQuery: GET_SHIPPING_METHODS
}
});
} = useShippingMethods({ ...ShippingMethodsOperations });

const classes = mergeClasses(defaultClasses, props.classes);

Expand Down Expand Up @@ -74,13 +69,3 @@ const ShippingMethods = props => {
};

export default ShippingMethods;

export const GET_SHIPPING_METHODS = gql`
query GetShippingMethods($cartId: String!) {
cart(cart_id: $cartId) @connection(key: "Cart") {
id
...ShippingMethodsFragment
}
}
${ShippingMethodsFragment}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import gql from 'graphql-tag';
* It is intentionally not included in the CartPageFragment. Make sure you are
* conscious about the side effects when including it in queries and mutations.
*/
export const AvailableShippingMethodsFragment = gql`
fragment AvailableShippingMethodsFragment on Cart {
export const AvailableShippingMethodsCartFragment = gql`
fragment AvailableShippingMethodsCartFragment on Cart {
id
shipping_addresses {
available_shipping_methods {
Expand All @@ -25,8 +25,8 @@ export const AvailableShippingMethodsFragment = gql`
}
`;

export const SelectedShippingMethodFragment = gql`
fragment SelectedShippingMethodFragment on Cart {
export const SelectedShippingMethodCartFragment = gql`
fragment SelectedShippingMethodCartFragment on Cart {
id
shipping_addresses {
selected_shipping_method {
Expand All @@ -37,11 +37,11 @@ export const SelectedShippingMethodFragment = gql`
}
`;

export const ShippingMethodsFragment = gql`
fragment ShippingMethodsFragment on Cart {
export const ShippingMethodsCartFragment = gql`
fragment ShippingMethodsCartFragment on Cart {
id
...AvailableShippingMethodsFragment
...SelectedShippingMethodFragment
...AvailableShippingMethodsCartFragment
...SelectedShippingMethodCartFragment
shipping_addresses {
country {
code
Expand All @@ -52,6 +52,6 @@ export const ShippingMethodsFragment = gql`
}
}
}
${AvailableShippingMethodsFragment}
${SelectedShippingMethodFragment}
${AvailableShippingMethodsCartFragment}
${SelectedShippingMethodCartFragment}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import RadioGroup from '../../../RadioGroup';
import { CartPageFragment } from '../../cartPageFragments.gql';
import ShippingRadio from './shippingRadio';
import defaultClasses from './shippingRadios.css';
import { SelectedShippingMethodFragment } from './shippingMethodsFragments';
import { SelectedShippingMethodCartFragment } from './shippingMethodsFragments.gql';

const ShippingRadios = props => {
const {
Expand Down Expand Up @@ -70,15 +70,15 @@ export const SET_SHIPPING_METHOD_MUTATION = gql`
cart {
id
...CartPageFragment
...SelectedShippingMethodFragment
...SelectedShippingMethodCartFragment
# Intentionally do not re-fetch available methods because
# a) they are wrong in the mutation response
# b) it is expensive to recalculate.
}
}
}
${CartPageFragment}
${SelectedShippingMethodFragment}
${SelectedShippingMethodCartFragment}
`;

ShippingRadios.propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Icon from '../../Icon';
import Image from '../../Image';
import defaultClasses from './product.css';
import { CartPageFragment } from '../cartPageFragments.gql';
import { AvailableShippingMethodsFragment } from '../PriceAdjustments/ShippingMethods/shippingMethodsFragments';
import { AvailableShippingMethodsCartFragment } from '../PriceAdjustments/ShippingMethods/shippingMethodsFragments.gql';
const IMAGE_SIZE = 100;

const errorIcon = <Icon src={AlertCircleIcon} attrs={{ width: 18 }} />;
Expand Down Expand Up @@ -129,12 +129,12 @@ export const REMOVE_ITEM_MUTATION = gql`
cart {
id
...CartPageFragment
...AvailableShippingMethodsFragment
...AvailableShippingMethodsCartFragment
}
}
}
${CartPageFragment}
${AvailableShippingMethodsFragment}
${AvailableShippingMethodsCartFragment}
`;

export const UPDATE_QUANTITY_MUTATION = gql`
Expand All @@ -152,10 +152,10 @@ export const UPDATE_QUANTITY_MUTATION = gql`
cart {
id
...CartPageFragment
...AvailableShippingMethodsFragment
...AvailableShippingMethodsCartFragment
}
}
}
${CartPageFragment}
${AvailableShippingMethodsFragment}
${AvailableShippingMethodsCartFragment}
`;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';

import { ShippingInformationFragment } from '../shippingInformationFragments.gql';
import { ShippingMethodsFragment } from '../../ShippingMethod/shippingMethodFragments.gql';
import { ShippingMethodsCheckoutFragment } from '../../ShippingMethod/shippingMethodFragments.gql';

export const SET_SHIPPING_INFORMATION_MUTATION = gql`
mutation SetShippingInformation(
Expand All @@ -25,12 +25,12 @@ export const SET_SHIPPING_INFORMATION_MUTATION = gql`
cart {
id
...ShippingInformationFragment
...ShippingMethodsFragment
...ShippingMethodsCheckoutFragment
}
}
}
${ShippingInformationFragment}
${ShippingMethodsFragment}
${ShippingMethodsCheckoutFragment}
`;

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import gql from 'graphql-tag';
import { PriceSummaryFragment } from '@magento/venia-ui/lib/components/CartPage/PriceSummary/priceSummaryFragments';

import {
AvailableShippingMethodsFragment,
SelectedShippingMethodFragment
AvailableShippingMethodsCheckoutFragment,
SelectedShippingMethodCheckoutFragment
} from './shippingMethodFragments.gql';

export const GET_SELECTED_AND_AVAILABLE_SHIPPING_METHODS = gql`
query getSelectedAndAvailableShippingMethods($cartId: String!) {
cart(cart_id: $cartId) @connection(key: "Cart") {
id
...AvailableShippingMethodsFragment
...SelectedShippingMethodFragment
...AvailableShippingMethodsCheckoutFragment
...SelectedShippingMethodCheckoutFragment
}
}
${AvailableShippingMethodsFragment}
${SelectedShippingMethodFragment}
${AvailableShippingMethodsCheckoutFragment}
${SelectedShippingMethodCheckoutFragment}
`;

export const SET_SHIPPING_METHOD = gql`
Expand All @@ -29,15 +29,15 @@ export const SET_SHIPPING_METHOD = gql`
) @connection(key: "setShippingMethodsOnCart") {
cart {
id
...SelectedShippingMethodFragment
...SelectedShippingMethodCheckoutFragment
...PriceSummaryFragment
# Intentionally do not re-fetch available methods because
# a) they are wrong in the mutation response
# b) it is expensive to recalculate.
}
}
}
${SelectedShippingMethodFragment}
${SelectedShippingMethodCheckoutFragment}
${PriceSummaryFragment}
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import gql from 'graphql-tag';
* causes the backend to make remote queries to carriers for real-time data.
* Make sure you are conscious about the side effects when including it in queries and mutations.
*/
export const AvailableShippingMethodsFragment = gql`
fragment AvailableShippingMethodsFragment on Cart {
export const AvailableShippingMethodsCheckoutFragment = gql`
fragment AvailableShippingMethodsCheckoutFragment on Cart {
id
shipping_addresses {
available_shipping_methods {
Expand All @@ -24,8 +24,8 @@ export const AvailableShippingMethodsFragment = gql`
}
`;

export const SelectedShippingMethodFragment = gql`
fragment SelectedShippingMethodFragment on Cart {
export const SelectedShippingMethodCheckoutFragment = gql`
fragment SelectedShippingMethodCheckoutFragment on Cart {
id
shipping_addresses {
selected_shipping_method {
Expand All @@ -41,11 +41,11 @@ export const SelectedShippingMethodFragment = gql`
}
`;

export const ShippingMethodsFragment = gql`
fragment ShippingMethodsFragment on Cart {
export const ShippingMethodsCheckoutFragment = gql`
fragment ShippingMethodsCheckoutFragment on Cart {
id
...AvailableShippingMethodsFragment
...SelectedShippingMethodFragment
...AvailableShippingMethodsCheckoutFragment
...SelectedShippingMethodCheckoutFragment
shipping_addresses {
country {
code
Expand All @@ -56,6 +56,6 @@ export const ShippingMethodsFragment = gql`
}
}
}
${AvailableShippingMethodsFragment}
${SelectedShippingMethodFragment}
${AvailableShippingMethodsCheckoutFragment}
${SelectedShippingMethodCheckoutFragment}
`;

0 comments on commit e69419d

Please sign in to comment.