Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PWA-1658] Move graphql-cli-validate-magento-pwa-queries to @magento scope #3198

Merged
merged 14 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const graphQLConfig = require('./graphql.config');

const config = {
parser: 'babel-eslint',
plugins: ['react'],
extends: ['@magento'],
rules: {
'no-prototype-builtins': 'off',
'no-undef': 'off',
'no-useless-escape': 'off',
'react/jsx-no-literals': [
Expand All @@ -15,7 +18,38 @@ const config = {
noStrings: true
}
]
}
},
overrides: [
{
files: ['**/*.gql.js'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some files named *.gql.ce.js and .gql.ee.js which I believe will get missed by this rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated pattern in b9de346

processor: '@graphql-eslint/graphql'
},
{
files: ['*.graphql'],
parser: '@graphql-eslint/eslint-plugin',
parserOptions: {
operations: graphQLConfig.documents,
schema: graphQLConfig.schema,
schemaOptions: {
assumeValid: true,
method: 'GET'
},
skipGraphQLConfig: true
},
plugins: ['@graphql-eslint'],
rules: {
'@graphql-eslint/known-directives': 'error',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only added a small subset of rules here from packages/graphql-cli-validate-magento-pwa-queries/lib/index.js. When I added all the validation rules listed in that file, the linter blew up with errors, so I suspect those validation rules weren't working as expected. Trying to keep this scope minimal to just feature parity with what we had before, which I why I selected this subset of rules that were working.

'@graphql-eslint/naming-convention': [
'error',
{
ObjectTypeDefinition: 'PascalCase',
leadingUnderscore: 'allow'
}
],
'@graphql-eslint/require-id-when-available': 'error'
}
}
]
};

module.exports = config;
31 changes: 31 additions & 0 deletions graphql.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const path = require('path');
require('dotenv').config({
path: path.resolve(process.cwd(), 'packages/venia-concept/.env')
});

const excludePatterns =
process.env.MAGENTO_BACKEND_EDITION === 'EE'
? ['!**/*.ce.js']
: ['!**/*.ee.js'];

const config = {
schema: [
`${process.env.MAGENTO_BACKEND_URL}/graphql`,
'**/client-schema.graphql'
],
documents: [
'./packages/{peregrine,venia-ui,venia-concept}/{lib,src}/**/*.{js,graphql,gql}',
...excludePatterns
],
extensions: {
codegen: {
generates: {
'./merged-schema.v4.json': {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New config structure for graphql-config@4. This codegen is actually broken until we fix a lot of other naming collisions, so I may remove this until we can resolve those.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed codegen section in 52ed88d

plugins: ['introspection']
}
}
}
}
};

module.exports = config;
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"packages/babel-preset-peregrine",
"packages/create-pwa",
"packages/extensions/*",
"packages/graphql-cli-validate-magento-pwa-queries",
"packages/pagebuilder",
"packages/peregrine",
"packages/pwa-buildpack",
Expand Down Expand Up @@ -41,26 +40,29 @@
"test:ci": "jest --no-cache --max-workers=3 --json --outputFile=test-results.json",
"test:debug": "node --inspect-brk node_modules/.bin/jest --no-cache --no-coverage --runInBand --testTimeout 86400",
"test:dev": "jest --watch",
"validate-queries": "yarn venia run validate-queries",
"validate-queries": "graphql validate --keepClientFields --noStrictFragments",
"venia": "yarn workspace @magento/venia-concept",
"watch:all": "node scripts/watch-all.js",
"watch:venia": "yarn venia run watch"
},
"devDependencies": {
"@babel/plugin-transform-runtime": "~7.4.4",
"@graphql-cli/validate": "~2.1.0",
"@graphql-eslint/eslint-plugin": "~1.0.1",
"@magento/eslint-config": "~1.5.0",
"@types/jest": "~25.2.1",
"babel-eslint": "~10.1.0",
"babel-plugin-dynamic-import-node": "~2.2.0",
"babel-plugin-graphql-tag": "~2.0.0",
"caller-id": "~0.1.0",
"chalk": "~2.4.2",
"chokidar": "~2.1.2",
"coveralls": "~3.0.3",
"danger": "^7.1.4",
"eslint": "~5.14.1",
"dotenv": "~6.2.0",
"eslint": "~7.27.0",
"eslint-config-prettier": "~6.0.0",
"eslint-plugin-babel": "~5.3.0",
"eslint-plugin-graphql": "~3.0.3",
"eslint-plugin-jsx-a11y": "~6.2.1",
"eslint-plugin-node": "~8.0.1",
"eslint-plugin-package-json": "~0.1.4",
Expand All @@ -69,6 +71,10 @@
"execa": "~1.0.0",
"figures": "~2.0.0",
"first-run": "~2.0.0",
"graphql": "~15.5.0",
"graphql-cli": "~4.1.0",
"graphql-config": "~3.3.0",
"graphql-tag": "~2.12.4",
"identity-obj-proxy": "~3.0.0",
"jest": "~26.0.1",
"jest-fetch-mock": "~2.1.1",
Expand All @@ -83,9 +89,6 @@
"sharp": "~0.23.3"
},
"resolutions": {
"graphql": "~14.3.1",
"**/graphql-cli/npm-run": "~5.0.0",
"**/graphql-cli/graphql-playground-middleware-express": "~1.7.18",
"https-proxy-agent": "~2.2.3"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extend type StoreConfig {
payment_checkmo_payable_to: String
payment_checkmo_mailing_address: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { gql } from '@apollo/client';
export const GET_CHECKMO_CONFIG_DATA = gql`
query storeConfigData {
storeConfig {
id
payment_checkmo_payable_to @client
payment_checkmo_mailing_address @client
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ test('renders a Block component', () => {

test('renders a Block component with all props configured and Page Builder rich content', () => {
const MockRow = () => 'Row';
// eslint-disable-next-line no-import-assign
config.getContentTypeConfig = jest.fn().mockImplementation(contentType => {
if (contentType === 'row') {
return {
Expand Down
3 changes: 3 additions & 0 deletions packages/pagebuilder/lib/__tests__/factory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test('factory should render instance of content type', () => {
}
};
const TestComponent = () => <mock-TestComponent />;
// eslint-disable-next-line no-import-assign
config.getContentTypeConfig = jest.fn().mockImplementation(contentType => {
if (contentType === 'test') {
return {
Expand Down Expand Up @@ -52,6 +53,7 @@ test('factory should render all children content types', () => {
<mock-ParentComponent>{children}</mock-ParentComponent>
);
const ChildComponent = () => <mock-ChildComponent />;
// eslint-disable-next-line no-import-assign
config.getContentTypeConfig = jest.fn().mockImplementation(contentType => {
if (contentType === 'parent') {
return {
Expand Down Expand Up @@ -95,6 +97,7 @@ test('factory should not render hidden instance of a content type', () => {
}
};
const TestComponent = () => <mock-TestComponent />;
// eslint-disable-next-line no-import-assign
config['contentTypesConfig'] = {
test: {
configAggregator: () => {
Expand Down
10 changes: 0 additions & 10 deletions packages/peregrine/.eslintrc.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ import typePolicies from '../../../../Apollo/policies';

import useGiftOptions from '../useGiftOptions';

/* eslint-disable graphql/template-strings */
const GET_GIFT_OPTIONS = gql`
query getGiftOptions($cartId: String!) {
cart(cart_id: $cartId) @client {
cart(cart_id: $cartId) {
id
include_gift_receipt
include_printed_card
gift_message
include_gift_receipt @client
include_printed_card @client
local_gift_message @client
}
}
`;
/* eslint-enable graphql/template-strings */

jest.mock('@magento/peregrine/lib/context/cart', () => {
const state = {
Expand Down Expand Up @@ -68,7 +66,7 @@ beforeEach(() => {
id: 'cart123',
include_gift_receipt: true,
include_printed_card: false,
gift_message: 'GiftMessage'
local_gift_message: 'GiftMessage'
}
});
});
Expand Down Expand Up @@ -133,7 +131,7 @@ test('it updates cache after updating gift message', async () => {
expect(cacheWriteSpy.mock.calls[0][0]).toMatchObject({
data: {
cart: {
gift_message: 'Hello World'
local_gift_message: 'Hello World'
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const useGiftOptions = props => {
id: cartId,
include_gift_receipt: includeGiftReceipt,
include_printed_card: includePrintedCard,
gift_message: giftMessage,
local_gift_message: giftMessage,
...optionsToUpdate
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ const useGiftOptions = props => {
return throttle(
(updateGiftOptions, newGiftMessage) => {
updateGiftOptions({
gift_message: newGiftMessage
local_gift_message: newGiftMessage
});
},
1000,
Expand Down Expand Up @@ -127,12 +127,12 @@ const useGiftOptions = props => {
const {
include_gift_receipt,
include_printed_card,
gift_message
local_gift_message
} = data.cart;

setIncludeGiftReceipt(include_gift_receipt);
setIncludePrintedCard(include_printed_card);
setGiftMessage(gift_message);
setGiftMessage(local_gift_message);
}
}, [setIncludeGiftReceipt, setIncludePrintedCard, data]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ import { gql } from '@apollo/client';
import { PriceSummaryFragment } from '../../CartPage/PriceSummary/priceSummaryFragments.gql';
import { AvailablePaymentMethodsFragment } from '../PaymentInformation/paymentInformation.gql';

// We disable linting for local fields because there is no way to add them to
// the fetched schema. Additionally, since we don't want to make a network call
// for "id" we disable "required-fields"
// https://github.com/apollographql/eslint-plugin-graphql/issues/99
/* eslint-disable graphql/template-strings */
export const GET_IS_BILLING_ADDRESS_SAME = gql`
query getIsBillingAddressSame($cartId: String!) {
cart(cart_id: $cartId) @client {
cart(cart_id: $cartId) {
id
isBillingAddressSame
isBillingAddressSame @client
}
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,23 @@ import { gql } from '@apollo/client';
import { PriceSummaryFragment } from '../../CartPage/PriceSummary/priceSummaryFragments.gql';
import { AvailablePaymentMethodsFragment } from './paymentInformation.gql';

// We disable linting for local fields because there is no way to add them to
// the fetched schema. Additionally, since we don't want to make a network call
// for "id" we disable "required-fields"
// https://github.com/apollographql/eslint-plugin-graphql/issues/99
/* eslint-disable graphql/template-strings */
export const GET_IS_BILLING_ADDRESS_SAME = gql`
query getIsBillingAddressSame($cartId: String!) {
cart(cart_id: $cartId) @client {
cart(cart_id: $cartId) {
id
isBillingAddressSame
isBillingAddressSame @client
}
}
`;

export const GET_PAYMENT_NONCE = gql`
query getPaymentNonce($cartId: String!) {
cart(cart_id: $cartId) @client {
cart(cart_id: $cartId) {
id
paymentNonce
paymentNonce @client
}
}
`;
/* eslint-enable graphql/template-strings */

export const GET_BILLING_ADDRESS = gql`
query getBillingAddress($cartId: String!) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,15 @@ export const GET_PAYMENT_INFORMATION = gql`
}
${AvailablePaymentMethodsFragment}
`;
// We disable linting for local fields because there is no way to add them to
// the fetched schema.
// https://github.com/apollographql/eslint-plugin-graphql/issues/99
/* eslint-disable graphql/template-strings */

export const GET_PAYMENT_NONCE = gql`
query getPaymentNonce($cartId: String!) {
cart(cart_id: $cartId) @client {
cart(cart_id: $cartId) {
id
paymentNonce
paymentNonce @client
}
}
`;
/* eslint-enable graphql/template-strings */

export const SET_BILLING_ADDRESS = gql`
mutation setBillingAddress(
Expand Down
5 changes: 0 additions & 5 deletions packages/peregrine/lib/talons/Header/currencySwitcher.gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ export const CUSTOM_TYPES = {
}
};

// We disable linting for local fields because there is no way to add them to
// the fetched schema.
// https://github.com/apollographql/eslint-plugin-graphql/issues/99
/* eslint-disable graphql/template-strings */
export const GET_CURRENCY = gql`
query getCurrencyData {
currency {
Expand All @@ -38,7 +34,6 @@ export const GET_CURRENCY = gql`
}
}
`;
/* eslint-enable graphql/template-strings */

export default {
getCurrencyQuery: GET_CURRENCY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ export const ADD_TO_WISHLIST = gql`
}
`;

/* eslint-disable graphql/template-strings */
export const GET_PRODUCTS_IN_WISHLISTS = gql`
query GetProductsInWishlistsForGallery {
customerWishlistProducts @client
}
`;
/* eslint-enable graphql/template-strings */

export default {
addProductToWishlistMutation: ADD_TO_WISHLIST,
Expand Down
1 change: 1 addition & 0 deletions packages/peregrine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"fast-glob": "~3.2.4"
},
"devDependencies": {
"@apollo/client": "~3.1.2",
"@magento/eslint-config": "~1.5.0",
"@testing-library/react-hooks": "~5.0.3",
"intl": "~1.2.5",
Expand Down
Loading