Skip to content
New issue

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

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

Already on GitHub? # to your account

Remove Mutation PII while still updating the Cache correctly #2240

Merged
merged 15 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from 14 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
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ describe('handler', () => {
});

test('it creates a validator with the correct configuration', async () => {
const expectedRule = [
'error',
// Act.
await plugin.handler(mockContext, mockArgs);

// Assert.
const ruleTargets = [
// These objects are derived from mockArgs.
{
env: 'apollo',
Expand All @@ -162,8 +165,7 @@ describe('handler', () => {
schemaJsonFilepath: 'unit test'
}
];

await plugin.handler(mockContext, mockArgs);
const warnRule = ['warn', ...ruleTargets];

const lintConfiguration = eslintCLIEngineSpy.mock.calls[0][0];

Expand All @@ -186,24 +188,20 @@ describe('handler', () => {

const templateStringsRule =
lintConfiguration.rules['graphql/template-strings'];
expect(templateStringsRule).toEqual(expectedRule);
expect(templateStringsRule).toBeInstanceOf(Array);
expect(templateStringsRule[0]).toBe('error');
expect(templateStringsRule[1]).toEqual(
expect.objectContaining({
env: expect.any(String),
projectName: expect.any(String),
schemaJsonFilepath: expect.any(String),
validators: expect.any(Array)
})
);

const deprecatedFieldsRule =
lintConfiguration.rules['graphql/no-deprecated-fields'];
expect(deprecatedFieldsRule).toEqual([
'warn',
// These objects are derived from mockArgs.
{
env: 'apollo',
projectName: 'myApp',
schemaJsonFilepath: 'unit test'
},
{
env: 'literal',
projectName: 'myApp',
schemaJsonFilepath: 'unit test'
}
]);
expect(deprecatedFieldsRule).toEqual(warnRule);

expect(lintConfiguration.useEslintrc).toBe(false);
});
Expand Down
76 changes: 66 additions & 10 deletions packages/graphql-cli-validate-magento-pwa-queries/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ async function validateQueries(context, argv) {
process.exit(exitCodes.SUCCESS);
}
}

process.exit(0);
} catch (e) {
const message = e.message ? e.message : e;
context.spinner.fail(`An error occurred:\n${message}`);
Expand All @@ -134,24 +132,82 @@ function getValidator({ clients, project, schemaPath }) {
schemaJsonFilepath: schemaPath
}));

const ruleDefinition = ['error', ...clientRules];
const error = ['error', ...clientRules];
const warn = ['warn', ...clientRules];

/*
* Here we explicitly list the validators for the graphql/template-strings rule to use.
*
* We'd like to use the special value 'all' but we have to disable some validators due
* to how PWA Studio uses GraphQL.
*
* @see https://github.com/apollographql/eslint-plugin-graphql#selecting-validation-rules
*/
const validators = [
'ExecutableDefinitions',
'FieldsOnCorrectType',
'FragmentsOnCompositeTypes',
'KnownArgumentNames',
/*
* PWA Studio queries sometimes use the @connection directive, which is Apollo-specific.
*/
// 'KnownDirectives',
/*
* PWA Studio sometimes uses fragments imported from other JS files.
* The parser does not recognize these.
*/
// 'KnownFragmentNames',
'KnownTypeNames',
'LoneAnonymousOperation',
'NoFragmentCycles',
'NoUndefinedVariables',
/*
* PWA Studio sometimes defines fragments for use by other JS files.
*/
// 'NoUnusedFragments',
'NoUnusedVariables',
'OverlappingFieldsCanBeMerged',
'PossibleFragmentSpreads',
'ProvidedRequiredArguments',
'ScalarLeafs',
'SingleFieldSubscriptions',
'UniqueArgumentNames',
'UniqueDirectivesPerLocation',
'UniqueFragmentNames',
'UniqueInputFieldNames',
'UniqueOperationNames',
'UniqueVariableNames',
'ValuesOfCorrectType',
'VariablesAreInputTypes',
/*
* The eslint-plugin-graphql docs may be out of date,
* this doesn't appear to be a legitimate validator anymore.
*/
// 'VariablesDefaultValueAllowed',
'VariablesInAllowedPosition'
];

const linterConfiguration = {
parser: 'babel-eslint',
plugins: ['graphql'],
rules: {
'graphql/capitalized-type-name': ruleDefinition,
'graphql/named-operations': ruleDefinition,
'graphql/no-deprecated-fields': ['warn', ...clientRules],
'graphql/capitalized-type-name': error,
'graphql/named-operations': error,
'graphql/no-deprecated-fields': warn,
'graphql/required-fields': [
'error',
...clients.map(clientName => ({
env: clientName,
schemaJsonFilepath: schemaPath,
...clientRules.map(rule => ({
...rule,
requiredFields: ['id']
}))
],
'graphql/template-strings': ruleDefinition
'graphql/template-strings': [
'error',
...clientRules.map(rule => ({
...rule,
validators
}))
]
},
useEslintrc: false
};
Expand Down
4 changes: 2 additions & 2 deletions packages/peregrine/lib/talons/Checkout/useAddressForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export const useAddressForm = props => {
fetchPolicy: 'no-cache'
});
const [setShippingAddressOnCart] = useMutation(
setShippingAddressOnCartMutation,
{ fetchPolicy: 'no-cache' }
setShippingAddressOnCartMutation
);

const values = useMemo(
() =>
fields.reduce((acc, key) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export const useCreateAccount = props => {
// personally identifiable information (PII). So we set fetchPolicy to 'no-cache'.
const [createAccount, { error: createAccountError }] = useMutation(
createAccountQuery,
{ fetchPolicy: 'no-cache' }
{
fetchPolicy: 'no-cache'
}
);
const [signIn, { error: signInError }] = useMutation(signInMutation, {
fetchPolicy: 'no-cache'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const SET_SHIPPING_ADDRESS_MUTATION = gql`
cart_id: $cartId
shipping_addresses: [{ address: $address }]
}
) {
) @connection(key: "setShippingAddressesOnCart") {
cart {
id
...CartPageFragment
Expand Down
1 change: 0 additions & 1 deletion packages/venia-ui/lib/queries/createAccount.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ mutation createAccount(
# which requires that at least one of the sub fields be returned.
customer {
id
email
}
}
}
1 change: 0 additions & 1 deletion packages/venia-ui/lib/queries/setGuestEmailOnCart.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mutation setGuestEmailOnCart($cartId: String!, $email: String!) {
setGuestEmailOnCart(input: { cart_id: $cartId, email: $email }) {
cart {
id
email
}
}
}
2 changes: 1 addition & 1 deletion packages/venia-ui/lib/queries/setShippingAddress.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mutation setShippingAddress(
}
]
}
) {
) @connection(key: "setShippingAddressesOnCart") {
cart {
id
shipping_addresses {
Expand Down