Project files

This commit is contained in:
2023-11-09 18:47:11 +01:00
parent 695abe054b
commit c415135aae
8554 changed files with 858111 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
# CHANGELOG
----
**NOTE:** This changelog is no longer maintained. Changes are now tracked in
the top level [`CHANGELOG.md`](https://github.com/apollographql/apollo-client/blob/master/CHANGELOG.md).
----
### vNext
- Allow `fetch` to be given as a configuration option to ApolloBoost.
[Issue #3578](https://github.com/apollographql/apollo-client/issues/3578)
[PR #3590](https://github.com/apollographql/apollo-client/pull/3590)
- The `apollo-boost` `ApolloClient` constructor warns about unsupported options.
[PR #3551](https://github.com/apollographql/apollo-client/pull/3551)
### 0.1.10
- No changes.
### 0.1.9
- No changes.
### 0.1.8
- Allow `cache` to be given as a configuration option to `ApolloBoost`.
[Issue #3220](https://github.com/apollographql/apollo-client/issues/3220)
[PR #3561](https://github.com/apollographql/apollo-client/pull/3561)
- Allow `headers` and `credentials` to be passed in as configuration
parameters to the `apollo-boost` `ApolloClient` constructor.
[PR #3098](https://github.com/apollographql/apollo-client/pull/3098)
### 0.1.7
- No public facing functionality changes.
- Various internal code cleanup, tooling and dependency changes.

View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2018 Meteor Development Group, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,77 @@
# apollo-boost
The fastest, easiest way to get started with Apollo Client!
Apollo Boost is a zero-config way to start using Apollo Client. It includes some sensible defaults, such as our recommended `InMemoryCache` and `HttpLink`, which come configured for you with our recommended settings.
## Quick start
First, install `apollo-boost`. If you don't have `graphql` & `react-apollo` already in your project, please install those too.
```shell
npm i apollo-boost graphql react-apollo -S
```
Next, create your client. Once you create your client, hook it up to your app by passing it to the `ApolloProvider` exported from `react-apollo`.
```js
import React from 'react';
import { render } from 'react-dom';
import ApolloClient from 'apollo-boost';
import { ApolloProvider } from 'react-apollo';
// Pass your GraphQL endpoint to uri
const client = new ApolloClient({ uri: 'https://nx9zvp49q7.lp.gql.zone/graphql' });
const ApolloApp = AppComponent => (
<ApolloProvider client={client}>
<AppComponent />
</ApolloProvider>
);
render(ApolloApp(App), document.getElementById('root'));
```
Awesome! Your ApolloClient is now connected to your app. Let's create our `<App />` component and make our first query:
```js
import React from 'react';
import { gql } from 'apollo-boost';
import { Query } from 'react-apollo';
const GET_MOVIES = gql`
query {
movie(id: 1) {
id
title
}
}
`
const App = () => (
<Query query={GET_MOVIES}>
{({ loading, error, data }) => {
if (loading) return <div>Loading...</div>;
if (error) return <div>Error :(</div>;
return (
<Movie title={data.movie.title} />
)
}}
</Query>
)
```
Time to celebrate! 🎉 You just made your first Query component. The Query component binds your GraphQL query to your UI so Apollo Client can take care of fetching your data, tracking loading & error states, and updating your UI via the `data` prop.
## What's in Apollo Boost
Apollo Boost includes some packages that we think are essential to developing with Apollo Client. Here's what's in the box:
- `apollo-client`: Where all the magic happens
- `apollo-cache-inmemory`: Our recommended cache
- `apollo-link-http`: An Apollo Link for remote data fetching
- `apollo-link-error`: An Apollo Link for error handling
- `graphql-tag`: Exports the `gql` function for your queries & mutations
The awesome thing about Apollo Boost is that you don't have to set any of this up yourself! Just specify a few options if you'd like to use these features and we'll take care of the rest. For a full list of available options, please refer to the Apollo Boost [configuration options](https://www.apollographql.com/docs/react/essentials/get-started.html#configuration-options) documentation.

View File

@@ -0,0 +1,52 @@
{
"name": "apollo-boost",
"version": "0.4.9",
"description": "The easiest way to get started with Apollo Client",
"author": "Peggy Rayzis <peggy@apollographql.com>",
"contributors": [
"James Baxley <james@apollographql.com>",
"Sashko Stubailo <sashko@apollographql.com>",
"James Burgess <jamesmillerburgess@gmail.com>"
],
"license": "MIT",
"main": "./lib/bundle.cjs.js",
"module": "./lib/bundle.esm.js",
"typings": "./lib/index.d.ts",
"sideEffects": false,
"repository": {
"type": "git",
"url": "git+https://github.com/apollographql/apollo-client.git"
},
"bugs": {
"url": "https://github.com/apollographql/apollo-client/issues"
},
"homepage": "https://github.com/apollographql/apollo-client#readme",
"scripts": {
"prepare": "npm run lint && npm run build",
"test": "tsc -p tsconfig.json --noEmit && jest",
"coverage": "jest --coverage",
"lint": "tslint -c \"../../config/tslint.json\" -p tsconfig.json src/*.ts",
"prebuild": "npm run clean",
"build": "tsc -b .",
"postbuild": "npm run bundle",
"watch": "tsc -w -p .",
"clean": "rm -rf coverage/* lib/*",
"prepublishOnly": "npm run build",
"bundle": "npx rollup -c rollup.config.js"
},
"dependencies": {
"apollo-cache": "^1.3.5",
"apollo-cache-inmemory": "^1.6.6",
"apollo-client": "^2.6.10",
"apollo-link": "^1.0.6",
"apollo-link-error": "^1.0.3",
"apollo-link-http": "^1.3.1",
"graphql-tag": "^2.4.2",
"ts-invariant": "^0.4.0",
"tslib": "^1.10.0"
},
"peerDependencies": {
"graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
},
"gitHead": "64cda6af5ebd1b917d8838790e043cc70dab4ed2"
}

View File

@@ -0,0 +1,202 @@
/* necessary for backward compat */
export * from 'apollo-client';
export * from 'apollo-link';
export * from 'apollo-cache-inmemory';
import { Operation, ApolloLink, Observable } from 'apollo-link';
import { HttpLink, UriFunction } from 'apollo-link-http';
import { onError, ErrorLink } from 'apollo-link-error';
import { ApolloCache } from 'apollo-cache';
import { InMemoryCache, CacheResolverMap } from 'apollo-cache-inmemory';
import gql from 'graphql-tag';
import ApolloClient, {
Resolvers,
LocalStateFragmentMatcher,
} from 'apollo-client';
import { DocumentNode } from 'graphql';
import { invariant } from 'ts-invariant';
export { gql, HttpLink };
type ClientStateConfig = {
cache?: ApolloCache<any>;
defaults?: Record<string, any>;
resolvers?: Resolvers | Resolvers[];
typeDefs?: string | string[] | DocumentNode | DocumentNode[];
fragmentMatcher?: LocalStateFragmentMatcher;
};
export interface PresetConfig {
request?: (operation: Operation) => Promise<void> | void;
uri?: string | UriFunction;
credentials?: string;
headers?: any;
fetch?: WindowOrWorkerGlobalScope['fetch'];
fetchOptions?: HttpLink.Options;
clientState?: ClientStateConfig;
onError?: ErrorLink.ErrorHandler;
cacheRedirects?: CacheResolverMap;
cache?: ApolloCache<any>;
name?: string;
version?: string;
resolvers?: Resolvers | Resolvers[];
typeDefs?: string | string[] | DocumentNode | DocumentNode[];
fragmentMatcher?: LocalStateFragmentMatcher;
assumeImmutableResults?: boolean;
}
// Yes, these are the exact same as the `PresetConfig` interface. We're
// defining these again so they can be used to verify that valid config
// options are being used in the `DefaultClient` constructor, for clients
// that aren't using Typescript. This duplication is unfortunate, and at
// some point can likely be adjusted so these items are inferred from
// the `PresetConfig` interface using a Typescript transform at compilation
// time. Unfortunately, TS transforms with rollup don't appear to be quite
// working properly, so this will have to be re-visited at some point.
// For now, when updating the properties of the `PresetConfig` interface,
// please also update this constant.
const PRESET_CONFIG_KEYS = [
'request',
'uri',
'credentials',
'headers',
'fetch',
'fetchOptions',
'clientState',
'onError',
'cacheRedirects',
'cache',
'name',
'version',
'resolvers',
'typeDefs',
'fragmentMatcher',
];
export default class DefaultClient<TCache> extends ApolloClient<TCache> {
constructor(config: PresetConfig = {}) {
if (config) {
const diff = Object.keys(config).filter(
key => PRESET_CONFIG_KEYS.indexOf(key) === -1,
);
if (diff.length > 0) {
invariant.warn(
'ApolloBoost was initialized with unsupported options: ' +
`${diff.join(' ')}`,
);
}
}
const {
request,
uri,
credentials,
headers,
fetch,
fetchOptions,
clientState,
cacheRedirects,
onError: errorCallback,
name,
version,
resolvers,
typeDefs,
fragmentMatcher,
} = config;
let { cache } = config;
invariant(
!cache || !cacheRedirects,
'Incompatible cache configuration. When not providing `cache`, ' +
'configure the provided instance with `cacheRedirects` instead.',
);
if (!cache) {
cache = cacheRedirects
? new InMemoryCache({ cacheRedirects })
: new InMemoryCache();
}
const errorLink = errorCallback
? onError(errorCallback)
: onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors) {
graphQLErrors.forEach(({ message, locations, path }) =>
// tslint:disable-next-line
invariant.warn(
`[GraphQL error]: Message: ${message}, Location: ` +
`${locations}, Path: ${path}`,
),
);
}
if (networkError) {
// tslint:disable-next-line
invariant.warn(`[Network error]: ${networkError}`);
}
});
const requestHandler = request
? new ApolloLink(
(operation, forward) =>
new Observable(observer => {
let handle: any;
Promise.resolve(operation)
.then(oper => request(oper))
.then(() => {
handle = forward(operation).subscribe({
next: observer.next.bind(observer),
error: observer.error.bind(observer),
complete: observer.complete.bind(observer),
});
})
.catch(observer.error.bind(observer));
return () => {
if (handle) {
handle.unsubscribe();
}
};
}),
)
: false;
const httpLink = new HttpLink({
uri: uri || '/graphql',
fetch,
fetchOptions: fetchOptions || {},
credentials: credentials || 'same-origin',
headers: headers || {},
});
const link = ApolloLink.from([errorLink, requestHandler, httpLink].filter(
x => !!x,
) as ApolloLink[]);
let activeResolvers = resolvers;
let activeTypeDefs = typeDefs;
let activeFragmentMatcher = fragmentMatcher;
if (clientState) {
if (clientState.defaults) {
cache.writeData({
data: clientState.defaults,
});
}
activeResolvers = clientState.resolvers;
activeTypeDefs = clientState.typeDefs;
activeFragmentMatcher = clientState.fragmentMatcher;
}
// super hacky, we will fix the types eventually
super({
cache,
link,
name,
version,
resolvers: activeResolvers,
typeDefs: activeTypeDefs,
fragmentMatcher: activeFragmentMatcher,
} as any);
}
}