This repository has been archived by the owner on May 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge logic from fusion-apollo-universal-client, export multiple plugins
#177 Co-authored-by: Giancarlo Anemone <ganemone@uber.com>
- Loading branch information
1 parent
6631b1b
commit 4897aeb
Showing
14 changed files
with
905 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** Copyright (c) 2018 Uber Technologies, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import test from 'tape-cup'; | ||
import { | ||
ApolloClientPlugin, | ||
GetApolloClientCacheToken, | ||
ApolloClientCredentialsToken, | ||
GetApolloClientLinksToken, | ||
ApolloClientDefaultOptionsToken, | ||
ApolloClientResolversToken, | ||
} from '../index.js'; | ||
|
||
test('exports', t => { | ||
t.ok(ApolloClientPlugin, 'exports ApolloClientPlugin'); | ||
t.ok(GetApolloClientCacheToken, 'exports GetApolloClientCacheToken'); | ||
t.ok(ApolloClientCredentialsToken, 'exports ApolloClientCredentialsToken'); | ||
t.ok(GetApolloClientLinksToken, 'exports ApolloClientAuthKeyToken'); | ||
t.ok(ApolloClientDefaultOptionsToken, 'exports ApolloClientAuthKeyToken'); | ||
t.ok(ApolloClientResolversToken, 'exports ApolloClientResolversToken'); | ||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** Copyright (c) 2018 Uber Technologies, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import {InMemoryCache} from 'apollo-cache-inmemory'; | ||
import App, {createPlugin} from 'fusion-core'; | ||
import {getSimulator} from 'fusion-test-utils'; | ||
import {ApolloClientToken} from '../../tokens'; | ||
import {ApolloLink} from 'apollo-link'; | ||
import {FetchToken} from 'fusion-tokens'; | ||
import unfetch from 'unfetch'; | ||
import test from 'tape-cup'; | ||
|
||
import {ApolloClientPlugin, GetApolloClientLinksToken} from '../index.js'; | ||
|
||
test('ApolloUniveralClient', async t => { | ||
const app = new App('el', el => el); | ||
app.register(GetApolloClientLinksToken, links => [ | ||
new ApolloLink(), | ||
...links, | ||
]); | ||
app.register(ApolloClientToken, ApolloClientPlugin); | ||
app.register(FetchToken, unfetch); | ||
|
||
const clients = []; | ||
const testPlugin = createPlugin({ | ||
deps: { | ||
universalClient: ApolloClientToken, | ||
}, | ||
middleware({universalClient}) { | ||
return async (ctx, next) => { | ||
const client = universalClient(ctx, {}); | ||
clients.push(client); | ||
t.ok(client.link); | ||
t.ok(client.cache instanceof InMemoryCache); | ||
// memoizes the client on ctx correctly | ||
t.equal(client, universalClient(ctx, {})); | ||
return next(); | ||
}; | ||
}, | ||
}); | ||
app.register(testPlugin); | ||
|
||
const simulator = getSimulator(app); | ||
await simulator.render('/'); | ||
await simulator.render('/'); | ||
t.equal(clients.length, 2); | ||
t.notEqual(clients[0], clients[1]); | ||
t.notEqual(clients[0].cache, clients[1].cache); | ||
t.end(); | ||
}); |
Oops, something went wrong.