Skip to content

Commit

Permalink
Avoid destructive mutations
Browse files Browse the repository at this point in the history
apollographql/apollo-client#4543

* Enable strict mode in all scripts
  • Loading branch information
AlexeyMatskevich committed Nov 26, 2019
1 parent f9a46eb commit 620e539
Show file tree
Hide file tree
Showing 38 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/javascript/components/AccountControl/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React from 'react'
import { IconButton, Menu, MenuItem } from '@material-ui/core'
import { AccountCircle } from '@material-ui/icons'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React from 'react'
import PropTypes from 'prop-types'
import clsx from 'clsx'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/CustomSnackbar/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { Snackbar } from '@material-ui/core'
import CustomSnackbarContent from './CustomSnackbarContent'
import React from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React, { useState } from 'react'
import clsx from 'clsx'
import useForm, { FormContext } from 'react-hook-form'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { FormControl, FormHelperText, Input, InputAdornment, InputLabel, makeStyles } from '@material-ui/core'
import EmailIcon from '@material-ui/icons/Email'
import React from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { FormControl, FormHelperText, Input, InputAdornment, InputLabel, makeStyles } from '@material-ui/core'
import EmailIcon from '@material-ui/icons/Email'
import React from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { FormControl, FormHelperText, IconButton, Input, InputAdornment, InputLabel } from '@material-ui/core'
import Visibility from '@material-ui/icons/Visibility'
import VisibilityOff from '@material-ui/icons/VisibilityOff'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { FormControl, FormHelperText, IconButton, Input, InputAdornment, InputLabel } from '@material-ui/core'
import Visibility from '@material-ui/icons/Visibility'
import VisibilityOff from '@material-ui/icons/VisibilityOff'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Form/Auth/Login/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React, { useState } from 'react'
import clsx from 'clsx'
import useForm, { FormContext } from 'react-hook-form'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Form/Auth/Registration/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React, { useState } from 'react'
import clsx from 'clsx'
import useForm, { FormContext } from 'react-hook-form'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Form/Auth/ResetPassword/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React, { useState } from 'react'
import clsx from 'clsx'
import useForm, { FormContext } from 'react-hook-form'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Form/Product/AddProduct/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React, { useState } from 'react'
import clsx from 'clsx'
import useForm, { FormContext } from 'react-hook-form'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { CircularProgress, makeStyles } from '@material-ui/core'
import React from 'react'
import { useFormContext } from 'react-hook-form'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { FormControl, FormHelperText, Input, InputLabel } from '@material-ui/core'
import debounce from 'lodash/debounce'
import React from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { FormControl, FormHelperText, Input, InputLabel } from '@material-ui/core'
import React from 'react'
import { useFormContext } from 'react-hook-form'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { FormControl, FormHelperText, Input, InputAdornment, InputLabel } from '@material-ui/core'
import React from 'react'
import { useFormContext } from 'react-hook-form'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { FormControl, FormHelperText, Input, InputAdornment, InputLabel } from '@material-ui/core'
import React from 'react'
import { useFormContext } from 'react-hook-form'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Form/Product/direct_upload.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { BlobUpload } from '@rails/activestorage/src/blob_upload'
import { CSRF } from '../../../utils/csrf'

Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Form/Product/get_file_media.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { FileChecksum } from '@rails/activestorage/src/file_checksum'

function calculateChecksum (file) {
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Form/helper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
export function isEmpty (obj) {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) { return false }
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Form/style.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { makeStyles } from '@material-ui/core'
import { green } from '@material-ui/core/colors'

Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Header/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React from 'react'
import { fade, makeStyles, withStyles } from '@material-ui/core/styles'
import { AppBar, Toolbar, IconButton, Badge, LinearProgress } from '@material-ui/core'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Home/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React from 'react'
import { useQuery } from '@apollo/react-hooks'
import { productsMeta } from './operations.graphql'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/NetworkError/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React from 'react'
import { useQuery } from '@apollo/react-hooks'
import { networkErrors } from '../operations.graphql'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Product/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React from 'react'
import { useParams } from 'react-router-dom'
import { product } from './operations.graphql'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Provider/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React from 'react'
import { ApolloProvider } from '@apollo/react-hooks'
import { createClient } from '../../utils/apollo'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Reviews/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React from 'react'
import { makeStyles } from '@material-ui/core/styles'
import List from '@material-ui/core/List'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/Search/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React from 'react'
import TextField from '@material-ui/core/TextField'
import Autocomplete from '@material-ui/lab/Autocomplete'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/ShopItem/NewItem/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React from 'react'
import { makeStyles } from '@material-ui/core/styles'
import Card from '@material-ui/core/Card'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/ShopItem/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React from 'react'
import { makeStyles } from '@material-ui/core/styles'
import {
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/ShopList/SearchList/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React, { useEffect, useState } from 'react'
import { Container, Grid, Typography } from '@material-ui/core'
import ShopItem from '../../ShopItem'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/ShopList/ShopListMobile/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React from 'react'
import { Container, Grid, Typography } from '@material-ui/core'
import ShopItem from '../../ShopItem'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/ShopList/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React, { useEffect, useState } from 'react'
import { Container, Grid, Typography } from '@material-ui/core'
import ShopItem from '../ShopItem'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/ShopList/style.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { makeStyles } from '@material-ui/core'

export const useStyles = makeStyles(theme => ({
Expand Down
1 change: 1 addition & 0 deletions app/javascript/packs/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import React from 'react'
import ReactDOM from 'react-dom'
import CssBaseline from '@material-ui/core/CssBaseline'
Expand Down
6 changes: 4 additions & 2 deletions app/javascript/utils/apollo.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import { ApolloClient } from 'apollo-client'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { HttpLink } from 'apollo-link-http'
Expand All @@ -7,7 +8,7 @@ import { resolvers, typeDefs } from './type'
import { networkErrors } from '../components/operations.graphql'
import { CSRF } from './csrf'

const cache = new InMemoryCache()
const cache = new InMemoryCache({ freezeResults: true })
const isLoggedIn = !!window.localStorage.getItem('refreshToken') || !!window.localStorage.getItem('token')

cache.writeData({
Expand Down Expand Up @@ -137,7 +138,8 @@ export const createClient = () => {
createHttpLink()
]),
typeDefs,
resolvers
resolvers,
assumeImmutableResults: true
})

client.onResetStore(() => { cache.writeData({ data: { isLoggedIn, networkErrors: [] } }) })
Expand Down
1 change: 1 addition & 0 deletions app/javascript/utils/csrf.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
'use strict'
export const CSRF = () => document.querySelector('meta[name="csrf-token"]').getAttribute('content')
1 change: 1 addition & 0 deletions app/javascript/utils/type.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
import gql from 'graphql-tag'

export const typeDefs = gql`
Expand Down

0 comments on commit 620e539

Please sign in to comment.