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

Upgrade ApolloClient package to version 3 #424

Merged
merged 11 commits into from
Oct 28, 2020
33 changes: 20 additions & 13 deletions react-components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ A context provider for user operations - sign in / sign-out, create user

A convenience wrapper for React components, encapsulating all the required contexts to run the app

## graphqlAuthLink

An ApolloLink instance that handles authorization on certain graphql requests (e.g.: cart mutations).
This is intended to be used when creating a new ApolloClient instance:

```javascript
import { ApolloClient, from, HttpLink, InMemoryCache } from '@apollo/client';
import {
graphqlAuthLink
} from '@adobe/aem-core-cif-react-components';

const client = new ApolloClient({
link: from([
graphqlAuthLink,
new HttpLink({ uri: graphqlEndpoint, headers: { Store: storeView } })]
),
cache: new InMemoryCache()
});
```

## Building the project

The project is built using the command `npm run build`. The build process bundles all the code into one client library which is placed in `../ui.apps/src/main/content/jcr_root/apps/core/cif/clientlibs/react-components/dist`.
Expand All @@ -60,19 +80,6 @@ The GraphQL endpoint is then available at `http://localhost:3002/graphql`.

If you develop for AEM on-prem installations, a proxy is included in our sample Dispatcher configuration (see [the dispacher configuration](../dispatcher) for details). You have to access AEM through the dispatcher (i.e. use https://localhost instead of http://localhost:4502).

### Generating Fragment types

In order to use fragments on queries, the Appolo client need prior knowledge of the types and relations.
See https://www.apollographql.com/docs/react/v2.6/data/fragments/#fragments-on-unions-and-interfaces

To acheive this, a JSON file needs to be generated by running

```
npm run generate-fragments <GRAPHQL_ENDPOINT>
```

This will be necessary with each new version of Magento GraphQL API release

### Building

To build the components you can use
Expand Down
1 change: 0 additions & 1 deletion react-components/fragmentTypes.json

This file was deleted.

Loading