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

chore: inline graphql-anywhere #301

Merged
merged 10 commits into from
Oct 26, 2022
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ An Apollo Link to easily try out GraphQL without a full server. It can be used t
## Installation

```bash
npm install apollo-link-rest apollo-link graphql graphql-anywhere qs --save
npm install apollo-link-rest @apollo/client graphql qs --save
or
yarn add apollo-link-rest apollo-link graphql graphql-anywhere qs
yarn add apollo-link-rest @apollo/client graphql qs
alessbell marked this conversation as resolved.
Show resolved Hide resolved
```

`apollo-link`, `graphql`, `qs` and `graphql-anywhere` are peer dependencies needed by `apollo-link-rest`.
`@apollo/client`, `graphql`, and `qs` are peer dependencies needed by `apollo-link-rest`.

## Usage

Expand Down
19 changes: 8 additions & 11 deletions docs/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,22 @@ You can start using ApolloClient in your app today, let's see how!

## Quick start

To get started, you need first to install apollo-client:
To get started, you need first to install @apollo/client:

```bash
npm install --save apollo-client
```

For an apollo client to work, you need a link and a cache, [more info here](https://www.apollographql.com/docs/react/basics/setup/#installation). Let's install the default in memory cache:

```bash
npm install --save apollo-cache-inmemory
npm install --save @apollo/client
```

Then it is time to install our link and its `peerDependencies`:

```bash
npm install --save apollo-link-rest apollo-link graphql graphql-anywhere qs
npm install --save apollo-link-rest apollo-link graphql qs
```

After this, you are ready to setup your apollo client:

```js
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloClient, InMemoryCache } from '@apollo/client';
import { RestLink } from 'apollo-link-rest';

// setup your `RestLink` with your endpoint
Expand All @@ -51,6 +44,10 @@ const client = new ApolloClient({
});
```

From the [Apollo Client "Get started" docs](https://www.apollographql.com/docs/react/get-started#step-3-initialize-apolloclient):

> `cache` is an instance of `InMemoryCache`, which Apollo Client uses to cache query results after fetching them.

Now it is time to write our first query, for this you need to install the `graphql-tag` package:

```bash
Expand Down
29 changes: 19 additions & 10 deletions examples/advanced/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"apollo-cache-inmemory": "1.x",
"apollo-client": "2.x",
"@apollo/client": "3.7.1",
"apollo-link-rest": "0.x",
"graphql": "0.x",
"graphql-anywhere": "4.x",
"graphql-tag": "2.x",
"qs": "^6.6.0",
"react": "16.x",
"react-apollo": "2.x",
"react-dom": "16.x",
"react-scripts": "1.x"
"graphql": "16.6.0",
"graphql-tag": "2.12.6",
"qs": "6.11.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-scripts": "5.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
4 changes: 1 addition & 3 deletions examples/advanced/src/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { Component } from 'react';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloProvider } from 'react-apollo';
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
import { RestLink } from 'apollo-link-rest';
import SearchShow from './SearchShow';
import './App.css';
Expand Down
6 changes: 4 additions & 2 deletions examples/advanced/src/SearchShow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { graphql } from 'react-apollo';
import { graphql } from '@apollo/client/react/hoc';
import gql from 'graphql-tag';

const Season = ({ summary, number, image }) => (
Expand Down Expand Up @@ -27,7 +27,9 @@ const Query = gql`

class ShowsResult extends Component {
render() {
const { data: { loading, error, show } } = this.props;
const {
data: { loading, error, show },
} = this.props;
if (loading) {
return <h4>Loading...</h4>;
}
Expand Down
6 changes: 4 additions & 2 deletions examples/advanced/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import './index.css';
import App from './App';

ReactDOM.render(<App />, document.getElementById('root'));
const container = document.getElementById('root');
const root = createRoot(container);
root.render(<App />);
29 changes: 19 additions & 10 deletions examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"apollo-cache-inmemory": "1.x",
"apollo-client": "2.x",
"@apollo/client": "3.7.1",
"apollo-link-rest": "0.x",
"graphql": "0.x",
"graphql-anywhere": "4.x",
"graphql-tag": "2.x",
"qs": "^6.6.0",
"react": "16.x",
"react-apollo": "2.x",
"react-dom": "16.x",
"react-scripts": "1.x"
"graphql": "16.6.0",
"graphql-tag": "2.12.6",
"qs": "6.11.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-scripts": "5.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
4 changes: 1 addition & 3 deletions examples/simple/src/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { Component } from 'react';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloProvider } from 'react-apollo';
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
import { RestLink } from 'apollo-link-rest';
import Person from './Person';
import './App.css';
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/src/Person.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { graphql } from 'react-apollo';
import { graphql } from '@apollo/client/react/hoc';
import gql from 'graphql-tag';

const Query = gql`
Expand Down
6 changes: 4 additions & 2 deletions examples/simple/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import './index.css';
import App from './App';

ReactDOM.render(<App />, document.getElementById('root'));
const container = document.getElementById('root');
const root = createRoot(container);
root.render(<App />);
49 changes: 28 additions & 21 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@
"private": true,
"main": "src/index.tsx",
"dependencies": {
"@types/graphql": "0.x",
"apollo-cache-inmemory": "1.x",
"apollo-client": "2.x",
"apollo-link": "1.x",
"@apollo/client": "3.7.1",
"apollo-link-rest": "0.x",
"graphql": "0.x",
"graphql-anywhere": "4.x",
"graphql-tag": "2.x",
"qs": "^6.6.0",
"react": "16.x",
"react-apollo": "2.x",
"react-dom": "16.x",
"react-scripts-ts": "2.x"
"graphql": "16.6.0",
"graphql-tag": "2.12.6",
"qs": "6.11.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-scripts": "5.0.1"
},
"scripts": {
"start": "react-scripts-ts start",
"build": "react-scripts-ts build",
"test": "react-scripts-ts test --env=jsdom",
"eject": "react-scripts-ts eject"
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"@types/jest": "23.x",
"@types/node": "10.x",
"@types/react": "16.x",
"@types/react-dom": "16.x",
"typescript": "2.9.x"
"@types/jest": "29.2.0",
"@types/node": "18.11.4",
"@types/react": "18.0.22",
"@types/react-dom": "18.0.7",
"typescript": "4.8.4"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
4 changes: 3 additions & 1 deletion examples/typescript/src/Repo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { graphql, ChildProps } from 'react-apollo';
import { graphql, ChildProps } from '@apollo/client/react/hoc';
import gql from 'graphql-tag';

// The Result type we expect back.
Expand Down Expand Up @@ -61,7 +61,9 @@ const query = gql`
// we expect the shape of the response to be and OwnProps is what we
// expect to be passed to this component.
const Repo = graphql<Result, OwnProps>(query, {
// @ts-ignore
options: ({ name }) => ({ variables: { name } }),
// @ts-ignore
})(RepoBase);

export { Repo };
1 change: 1 addition & 0 deletions examples/typescript/src/RepoSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class RepoSearch extends React.Component<{}, State> {
<option value="react-apollo">React Apollo</option>
<option value="apollo-client">Apollo Client</option>
</select>
{/* @ts-ignore */}
<Repo name={this.state.repo} />
</div>
);
Expand Down
12 changes: 6 additions & 6 deletions examples/typescript/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as React from 'react';
import { render } from 'react-dom';
import { createRoot } from 'react-dom/client';
import { RestLink } from 'apollo-link-rest';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloProvider } from 'react-apollo';
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';

import { RepoSearch } from './RepoSearch';

Expand All @@ -18,9 +16,11 @@ const client = new ApolloClient({
link,
});

render(
const container = document.getElementById('root')!;
const root = createRoot(container);

root.render(
<ApolloProvider client={client}>
<RepoSearch />
</ApolloProvider>,
document.getElementById('root'),
);
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"homepage": "https://github.com/apollographql/apollo-link-rest#readme",
"scripts": {
"build:browser": "browserify ./lib/bundle.umd.js -o=./lib/bundle.js --i @apollo/client/core --i @apollo/client/utilities --i apollo-utilities --i graphql --i react && npm run minify:browser",
"build:browser": "browserify ./lib/bundle.umd.js -o=./lib/bundle.js --i @apollo/client/core --i @apollo/client/utilities --i graphql --i react && npm run minify:browser",
"build": "tsc -p .",
"bundle": "rollup -c",
"clean": "rimraf lib/* coverage/* npm/*",
Expand Down Expand Up @@ -45,7 +45,6 @@
"peerDependencies": {
"@apollo/client": ">=3",
"graphql": ">=0.11",
"graphql-anywhere": ">=4",
"qs": ">=6"
},
"devDependencies": {
Expand All @@ -63,7 +62,6 @@
"danger": "6.x",
"fetch-mock": "7.x",
"graphql": "14.x",
"graphql-anywhere": "4.1.x",
"isomorphic-fetch": "2.2.x",
"jest": "23.x",
"jest-fetch-mock": "2.x",
Expand Down
2 changes: 0 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const globals = {
'@apollo/client/core': 'apolloClient.core',
'@apollo/client/utilities': 'apolloClient.utilities',
'@apollo/link-error': 'apolloLink.error',
'graphql-anywhere': 'graphqlAnywhere',
'graphql-anywhere/lib/async': 'graphqlAnywhere.async',
};

export default {
Expand Down
22 changes: 19 additions & 3 deletions src/restLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,27 @@ import {
checkDocument,
removeDirectivesFromDocument,
} from '@apollo/client/utilities';
import { graphql } from './utils/graphql';
import * as qs from 'qs';

import { graphql } from 'graphql-anywhere/lib/async';
import { Resolver, ExecInfo } from 'graphql-anywhere';
export type DirectiveInfo = {
[fieldName: string]: { [argName: string]: any };
};

import * as qs from 'qs';
export type ExecInfo = {
isLeaf: boolean;
resultKey: string;
directives: DirectiveInfo;
field: FieldNode;
};

export type Resolver = (
fieldName: string,
rootValue: any,
args: any,
context: any,
info: ExecInfo,
) => any;

export namespace RestLink {
export type URI = string;
Expand Down
Loading