1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
Commit graph

52 commits

Author SHA1 Message Date
Juan Olvera 89a4cabbd6 Change React version of examples to latest (#5990)
I changed the version to the following files:

- [x] - examples/with-next-css/package.json
- [x] - examples/with-draft-js/package.json
- [x] - examples/custom-server-polka/package.json
- [x] - examples/with-cerebral/package.json
- [x] - examples/with-zones/package.json
- [x] - examples/with-universal-configuration-runtime/package.json
- [x] - examples/with-apollo/package.json
- [x] - examples/with-higher-order-component/package.json
- [x] - examples/with-hashed-statics/package.json
- [x] - examples/with-pkg/package.json
- [x] - examples/with-jest/package.json
- [x] - examples/with-glamorous/package.json
- [x] - examples/with-custom-reverse-proxy/package.json
- [ ] - examples/with-emotion/package.json
- [x] - examples/with-styled-jsx-scss/package.json
- [x] - examples/with-styled-jsx-plugins/package.json

`with-emotion/package.json` already has the latest, so I guess it's other packabe. BUT I think we need to update this example with the latest version of `emotion` since it changed a little bit (for better).
2019-01-05 12:16:07 +01:00
Tim Neutkens 9c4eefcdbf
Add prettier for examples directory (#5909)
* Add prettier for examples directory

* Fix files

* Fix linting

* Add prettier script in case it has to be ran again
2018-12-17 17:34:32 +01:00
Matthew Francis Brunetti 7961946c07 withApollo example - move from old HOC APIs to new function-as-child APIs (#5241)
Since version 2.1, react-apollo is exposing some new components that use the function-as-child (or render-prop) pattern to let you connect apollo-client magic with your components. See the blog article: [New in React Apollo 2.1](https://www.apollographql.com/docs/react/react-apollo-migration.html)

If I'm not mistaken, it's generally agreed that this pattern is (where it works) superior to the HOC pattern, for reasons that are best explained here: https://cdb.reacttraining.com/use-a-render-prop-50de598f11ce 

So I updated the with-apollo example to use the new API, and IMO this code is much simpler and natural to read and understand, especially if you are not already familiar with Apollo's HOC APIs.

I broke up my changes into separate commits, for easier review. Commits with "Refactor" in the message accomplish the goal of switching to the new APIs while minimizing line-by-line differences (select "Hide whitespace changes" under "Diff settings"). Commits with "Clean up" in the message follow up the refactoring with trivial things like reorganizing code sections, renaming variables, etc.

For the components doing mutations, I chose not to use the `Mutation` component, since that doesn't really make sense to me; a mutation is something that happens at a point in time, so it's not meaningful to represent a mutation in the markup, which exists for a period of time. All that component does is expose a `mutate` function for a single specified mutation, and `result` data for a single firing of the mutation (which we don't need anyways; apollo handles updating the local data with the result). To me it seems simpler and more flexible to just get the apollo client via `ApolloConsumer` and call `.mutate()` on it. 

In case anyone is interested, here's what my version of `PostUpvoter` using the `Mutation` component looked like:

 <details>

```jsx
import React from 'react'
import { Mutation } from 'react-apollo'
import { gql } from 'apollo-boost'

export default function PostUpvoter ({ votes, id }) {
  return (
    <Mutation mutation={upvotePost}>
      {mutate => (
        <button onClick={() => upvote(id, votes + 1, mutate)}>
          {votes}
          <style jsx>{`
            button {
              background-color: transparent;
              border: 1px solid #e4e4e4;
              color: #000;
            }
            button:active {
              background-color: transparent;
            }
            button:before {
              align-self: center;
              border-color: transparent transparent #000000 transparent;
              border-style: solid;
              border-width: 0 4px 6px 4px;
              content: '';
              height: 0;
              margin-right: 5px;
              width: 0;
            }
          `}</style>
        </button>
      )}
    </Mutation>
  )
}

const upvotePost = gql`
  mutation updatePost($id: ID!, $votes: Int) {
    updatePost(id: $id, votes: $votes) {
      id
      __typename
      votes
    }
  }
`
function upvote (id, votes, mutate) {
  mutate({
    variables: { id, votes },
    optimisticResponse: {
      __typename: 'Mutation',
      updatePost: {
        __typename: 'Post',
        id,
        votes
      }
    }
  })
}
```

</details>

###

I'm happy with where things are at here, but I'm more than happy to address any comments, concerns, ideas for improvent!

Thanks!
2018-09-26 01:32:41 +02:00
Adam Lane 48d54c254f example with-apollo note that two render executions are expected (#5262)
Noting per https://github.com/zeit/next.js/issues/5050 for new users of Apollo that they should not be concerned about multiple renders.
2018-09-23 21:05:00 +02:00
Arek Mytych 2304300d68 Update GrpahQL dependencies (#5242)
Fixes the example with next.js@7

Fixes #5238
2018-09-21 11:49:24 +02:00
HaNdTriX 5ff7c0742c Lint examples (#4985)
* Lint examples/with-apollo-and-redux-saga

* Lint examples/with-apollo-auth

* Lint examples/with-apollo

* Lint exampels/with-google-analytics

* Lint examples/with-higher-order-component

* Lint examples/with-react-i18next

* Lint exampels/with-redux

* Lint exampels/with-relay-modern

* Lint examples/with-universal-configuration-runtime

* Add **/examples/**/lib/** to linter
2018-08-20 08:31:24 +02:00
Tim Phillips b990b29d2d Update Apollo links in examples (#4933) 2018-08-09 14:00:08 -07:00
Kenneth Luján Rosas dca2ca6f2b [with-apollo] simplify apolloState prop (#4755)
As seen on `with-apollo-auth` there are some things that need to be addressed here too.

* #4554 remove useless `apolloState` from App props on `getDataFromTree`
* #4563 simplify `apolloState` prop

Let me know if further changes/fixes are needed. 
Thank you 🎉
2018-07-12 18:59:28 +02:00
Michael Herold 5b3578e58f #4751 - Explicitly mention install when cloning examples (#4758)
Preferably this installation wouldn't be necessary, but in lieu of a fix...

#4751
2018-07-11 23:56:15 +02:00
NikitaVlaznev 728871b005 Apollo example: avoid double render in browser (#4734)
Apollo's getDataFromTree is supposed to be called during the server side rendering.
Being called in browser it fires an unnecessary fake render process and blocks components from rendering with loading=true.

Also there was a mistake in this code:

    // `getDataFromTree` renders the component first, the client is passed off as a property.
    // After that rendering is done using Next's normal rendering pipeline
    this.apolloClient = props.apolloClient || initApollo(props.apolloState.data)

**Apollo** component is not rendered by getDataFromTree actually, it renders the **App** directly, thus props.apolloClient will always be undefined.

This example was discussed here: https://github.com/zeit/next.js/issues/387.
2018-07-05 20:49:23 +02:00
Niklas Wagner dde20fc841 Added note for AWSAppSyncClient (#4611)
I had some trouble to get server side rendering with the AWSAppSyncClient working. I finally found a solution in https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/82 but it might be worth to share it here as well. Instead of adding a big code block to each file I'll just refer to this Pull Request.

______

In case you want to use the `AWSAppSyncClient` you just need to replace the `create()` function with this function:
```jsx
import AWSAppSyncClient from 'aws-appsync';
import { AUTH_TYPE } from 'aws-appsync/lib/link/auth-link';

function create(initialState) {
  const client = new AWSAppSyncClient({
    url: AWS_AppSync.graphqlEndpoint,
    region: AWS_AppSync.region,
    auth: {
      type: AUTH_TYPE.API_KEY,
      apiKey: AWS_AppSync.apiKey,

      // Amazon Cognito Federated Identities using AWS Amplify
      //credentials: () => Auth.currentCredentials(),

      // Amazon Cognito user pools using AWS Amplify
      // type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
      // jwtToken: async () => (await Auth.currentSession()).getIdToken().getJwtToken(),
    },
    disableOffline: true,
  }, {
    cache: new InMemoryCache().restore(initialState || {}),
    ssrMode: true
  });

  return client;
}
```
2018-06-29 10:08:26 +02:00
Jorge Cuadra 8082eddaef Remove unused import (patch) (#4493) 2018-05-29 19:33:21 +02:00
Tim Neutkens 6c0091fb7a
Add new apollo example using _app.js (#4286)
* Add new apollo example

* Update readme

* Update with-apollo to use _app.js

* Move withData to _app

* Make SSR work again

* Remove withData

* Use HOC to provide apolloClient

* Spread pageprops
2018-05-07 15:02:56 +02:00
James Hegedus f2e56609cd Examples: stabalise README format and create-next-app usage (#4009)
* Examples: clarify language around Yarn create & npx

* add missing READMEs and create-next-app usage

* suggest people tag jthegedus in firebase related issues

* add yarn alt instructions

* cerebraljs example readme & fixes
2018-04-03 14:19:05 +02:00
Wes Bos 3949c82bdf Add missing url prop (#4078)
This was causing react-apollo  to crash on any SSR page that needed the page's query to make the GraphQL queries. 

It's magically passed on the client, but we have to manually pass it to the composed component here
2018-03-29 18:01:12 +02:00
Will Meier 4570f2d050 Update with-apollo examples (#4067)
* Update with-apollo examples to include note about top-level withData HOC

* Update with-apollo examples to include note about top-level withData HOC
2018-03-28 22:30:42 +02:00
Prateek Rastogi 9470b91ba1 migrated from apollo-client-preset to apollo-boost (#4047) 2018-03-23 12:51:58 +01:00
Shaleen Jain cd1d9e0c35 with-apollo: Improve lib/withData (#3973)
* pass down getInitialProps ctx to ComposedComponent
* pass apollo client instance directly to getDataFromTree instead of through the ApolloProvider wrapper.
* Avoid redundant empty serverState initialization (It's always initialized)
2018-03-16 11:52:30 +01:00
James Hegedus b1d8b839dd Examples: use npx and yarn create to run create-next-app on examples (#4002)
* remove global npm install of create-next-app

* add npx to create-next-app command in examples

* add bash to shell snippets

* add yarn create to next-app command in examples

* fix READMEs named with lowercase

* change READMEs to use UPPERCASE
2018-03-14 09:09:46 +01:00
Sitian Liu 6de3ff9d78 Remove redux comment (#3792)
Apollo client 2.0 is no longer implemented with redux
2018-02-13 23:20:22 +01:00
Jon Espen Kvisler 4d9cf1940c [with-apollo] Use getDataFromTree in browser (#3457)
* use getDataFromTree in browser

* formatting

* removed ssrMode argument, not needed
2018-02-04 12:36:35 +01:00
Brice BERNARD 35ffad968c [with-apollo] Fix missing rootContext (#3468) 2017-12-18 11:25:06 +01:00
Tim Neutkens 24c1ac6ca9
Use canary for all example downloads (#3411) 2017-12-06 18:12:42 -08:00
Brice BERNARD 48ed89f93d [with-apollo] Fix warning about missing _allPostsMeta and more (#3397)
* Fix coding style

* Fix className type

* Upgrade deps

* Fix coding style of lib/

* Simplify onSubmit handler

* Fix missing missing _allPostsMeta warning

* Follow lint rules
2017-12-05 10:50:45 -08:00
Fouad Matin 2528779394 examples: add create-next-app (#3377)
* examples: add create-next-app

* fix with-typescript readme
2017-12-02 20:30:17 -08:00
Max Scher f0eacf66ea Add data node to serverState declaration (#3321)
The serverState variable definition did not include the data node, which
may cause parsing errors on the client-side.
  - add data: { } on line 23 within the apollo: { } object
2017-11-23 13:46:33 +01:00
Thomas Vogel abe0aebcc0 updated with-apollo example to update option API (#3296) 2017-11-16 11:18:25 +01:00
Kai Yen d72d3c09ef Fixed how credentials opt is passed to HttpLink (#3269)
Prior to react-apollo 2.0 createNetworkInterface accepted the credentials option in {opt: {credentials: 'policy'}}. HttpLink accepts it as {credentials: 'policy'}.
2017-11-13 12:20:59 +01:00
Leonardo Quixada b41d177609 Dropped isomorphic-fetch in examples in favor of isomorphic-unfetch. (#3230) 2017-11-04 15:05:16 +01:00
Jerome Fitzgerald a450502a0d [fix] with-apollo: Cannot read property 'data' (#3226)
* [fix] with-apollo: Cannot read property 'data'

When we create the initial serverState, we need to create the
 eventual construct of the Apollo Data to reside within

Later in the constructor this allows for the initApollo to either
 be generated from SSR, or to init from scratch.

Fixes
> Cannot read property 'data' of undefined
> TypeError: Cannot read property 'data' of undefined

* [refactor] with-apollo: reduce init `serverState`

No need to explicitly set `data` as empty.
This trims up 4 lines. 😀
2017-11-04 11:24:16 +01:00
Sebastian c0eca35810 with-apollo example using Apollo 2 (#3180)
* Updated dependencies related to Apollo and React.

* Updated libs with Apollo 2 new set of modules.

* Updated to Apollo 2 react integration modules.

* Updated withData to separate apollo state from the app's state.
2017-10-28 09:19:56 +02:00
Arunoda Susiripala c5c270c576 Merge master into v3-beta. 2017-07-06 12:24:31 +05:30
Jayden Seric ec2b76f83b Better data fetching error handling for Apollo examples (#2227)
* Display data fetching errors in Apollo examples.

* Prevent Apollo GraphQL errors from crashing SSR.

Also tidied a few comments in the vicinity.
2017-07-01 23:56:12 +02:00
Jayden Seric 9bbdfeca63 Component display name fixes for Apollo examples (#2211)
* Fix decorated component display name issues for Apollo examples.

* Fix linting errors and implement #2286
2017-07-01 23:51:20 +02:00
Thomas Preusse 3be175b466 Apollo Example: Fix duplicate head tags (#2362) 2017-06-28 19:07:21 +02:00
Adam Soffer 5d71434121 Remove warning when upvoting a post in apollo examples (#2190)
* Fix apollo warning and error when upvoting post

* Fix apollo warning and error when upvoting post in apollo-redux example as well
2017-06-08 19:26:40 +02:00
Roland Warmerdam f4d6cbfc19 Many improvements to the Apollo examples (#1905)
* Many improvements to the Apollo examples

* Use static properties
2017-05-11 00:23:11 +02:00
Paul Molluzzo d08e027a8c Add deploy now button to the top of all example READMEs (#1763)
* Add deploy now button to the top of all example READMEs

* Remove unnecessary whitespace changes
2017-04-22 14:51:51 +02:00
Tim Neutkens 7f0591896a Use latest version of Next for all examples (#1597)
* Use latest for all examples

* Update yarn.lock
2017-04-03 09:46:35 +05:30
Adam Soffer c2036e1326 Create separate Apollo example without Redux integration (#1483)
* Add minimal apollo example

* Update apollo example README

* Update apollo example demo link in README

* Fix button styles

* Fix show more button

* Alias demo url

* Include the data field on the Apollo store when hydrating

* Revert

* Include the data field on the Apollo store when hydrating per tpreusse's suggestion.

* Add example to faq section in README

* Sort by newest; Add active state to buttons

* Make optimization suggestions

* Use process.browser; inline props

* Pass wrapped component's initial props into component heirarchy if they exist

* Remove unnecessary sorting of array

* Update Apollo example

* Remove trailing comma

* Update reduxRootKey

* Remove unnecessary babelrc

* Update with-apollo example

- Remove use of deprecated 'reduxRootKey' option
- Add loading indicator inside pagination button

* Fix with-apollo example pagination; Pass initialState to ApolloClient

* Split apollo example into two (one with and without Redux integration)

* Rename createClient private function to _initClient

* Set initialState default parameter inside initClient function

* Remove redux dep from with-apollo example
2017-03-30 11:21:13 -07:00
Adam Soffer d5bd8c7d03 Update with-apollo example (#1394)
* Add minimal apollo example

* Update apollo example README

* Update apollo example demo link in README

* Fix button styles

* Fix show more button

* Alias demo url

* Include the data field on the Apollo store when hydrating

* Revert

* Include the data field on the Apollo store when hydrating per tpreusse's suggestion.

* Add example to faq section in README

* Sort by newest; Add active state to buttons

* Make optimization suggestions

* Use process.browser; inline props

* Pass wrapped component's initial props into component heirarchy if they exist

* Remove unnecessary sorting of array

* Update Apollo example

* Remove trailing comma

* Update reduxRootKey

* Remove unnecessary babelrc

* Update with-apollo example

- Remove use of deprecated 'reduxRootKey' option
- Add loading indicator inside pagination button
2017-03-14 23:41:55 +01:00
Jayden Seric 02e697cb0d Updated with-apollo example. (#1389)
- Deleted several unused dependencies.
- Updated dependencies.
- Simplified Apollo related imports thanks to react-apollo exporting apollo-client and graphql-tag since [v0.13.2](https://github.com/apollographql/react-apollo/blob/master/Changelog.md#0132).
- Tidied the readme and added a link to the Apollo docs.
2017-03-12 08:33:01 +01:00
Tim Suchanek 40573317f7 Update README.md (#1368)
Fix graph.cool link in example
2017-03-07 14:47:31 +01:00
Sébastien Dubois 6ede206d82 update link prefetch syntax in examples (#1276) 2017-02-25 15:54:42 +01:00
Lukas Strassel 4a73ccbb00 add react and react dom as peer (#1024)
- tackles #997
- add ./idea to gitignore for webstorm users
- update all the examples
2017-02-08 10:11:38 +05:30
Adam Soffer 01cc898450 Update Apollo example (#1021)
* Add minimal apollo example

* Update apollo example README

* Update apollo example demo link in README

* Fix button styles

* Fix show more button

* Alias demo url

* Include the data field on the Apollo store when hydrating

* Revert

* Include the data field on the Apollo store when hydrating per tpreusse's suggestion.

* Add example to faq section in README

* Sort by newest; Add active state to buttons

* Make optimization suggestions

* Use process.browser; inline props

* Pass wrapped component's initial props into component heirarchy if they exist

* Remove unnecessary sorting of array

* Update Apollo example

* Remove trailing comma

* Update reduxRootKey

* Remove unnecessary babelrc
2017-02-07 12:02:28 +01:00
Tim Neutkens 0820204646 Remove yarn.lock from examples (#912)
* Remove yarn.lock from examples

* Add yarn.lock to gitignore for examples

* Move yarn ignore to examples directory
2017-01-29 05:48:53 +05:30
Sébastien Dubois a3bec7666b with-apollo: Don't store Redux store and Apollo client in global namespace (#909)
* Add yarn lockfile

* Avoid storing Redux store and Apollo client in global namespace + don't create Apollo client when already existing in browser
2017-01-28 17:22:32 +01:00
Adam Soffer 8310f812ec Fix Apollo Example (#900)
* Add minimal apollo example

* Update apollo example README

* Update apollo example demo link in README

* Fix button styles

* Fix show more button

* Alias demo url

* Include the data field on the Apollo store when hydrating

* Revert

* Include the data field on the Apollo store when hydrating per tpreusse's suggestion.

* Add example to faq section in README

* Sort by newest; Add active state to buttons

* Make optimization suggestions

* Use process.browser; inline props

* Pass wrapped component's initial props into component heirarchy if they exist

* Remove unnecessary sorting of array
2017-01-27 17:06:17 +01:00
jcsmesquita 8922e7b63a Update README.md (#895)
Just adding download instructions
2017-01-26 23:19:12 +05:30