Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

Support Apollo Client 2.5 #457

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions examples/angular/games/src/app/graphql.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,29 @@ import {ApolloClientOptions} from 'apollo-client';
import {ApolloModule, APOLLO_OPTIONS} from 'apollo-angular';
import {HttpLinkModule, HttpLink} from 'apollo-angular-link-http';
import {InMemoryCache} from 'apollo-cache-inmemory';
import {LoonaModule, LoonaLink, LOONA_CACHE} from '@loona/angular';
import {LoonaModule} from '@loona/angular';

import {GamesState} from './games/games.state';

export function apolloFactory(
httpLink: HttpLink,
loonaLink: LoonaLink,
cache: InMemoryCache,
): ApolloClientOptions<any> {
const link = loonaLink.concat(
httpLink.create({
uri: 'https://graphql-games-example.glitch.me/',
}),
);
export function apolloFactory(httpLink: HttpLink): ApolloClientOptions<any> {
const link = httpLink.create({
uri: 'https://graphql-games-example.glitch.me/',
});

return {
link,
cache,
cache: new InMemoryCache(),
};
}

@NgModule({
imports: [CommonModule, LoonaModule.forRoot([GamesState])],
exports: [ApolloModule, HttpLinkModule, LoonaModule],
providers: [
{
provide: LOONA_CACHE,
useFactory() {
return new InMemoryCache();
},
},
{
provide: APOLLO_OPTIONS,
useFactory: apolloFactory,
deps: [HttpLink, LoonaLink, LOONA_CACHE],
deps: [HttpLink],
},
],
})
Expand Down
8 changes: 4 additions & 4 deletions examples/angular/lazy/src/app/books/books.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import gql from 'graphql-tag';

export class AddBook {
static mutation = gql`
mutation addBook($title: String!) @client {
addBook(title: $title)
mutation addBook($title: String!) {
addBook(title: $title) @client
}
`;

Expand All @@ -15,8 +15,8 @@ export class AddBook {
}

export const allBooks = gql`
query allBooks @client {
books {
query allBooks {
books @client {
id
title
}
Expand Down
34 changes: 12 additions & 22 deletions examples/angular/lazy/src/app/graphql.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,37 @@ import {CommonModule} from '@angular/common';
import {ApolloClientOptions} from 'apollo-client';
import {ApolloModule, APOLLO_OPTIONS} from 'apollo-angular';
import {InMemoryCache} from 'apollo-cache-inmemory';
import {
LoonaModule,
LoonaLink,
LOONA_CACHE,
Loona,
Actions,
} from '@loona/angular';
import {ApolloCache} from 'apollo-cache';
import {LoonaModule, Loona, Actions} from '@loona/angular';
import {ApolloLink, Observable} from 'apollo-link';

export function apolloFactory(
loonaLink: LoonaLink,
cache: ApolloCache<any>,
): ApolloClientOptions<any> {
// example does not work
export function apolloFactory(): ApolloClientOptions<any> {
return {
link: loonaLink,
cache,
link: new ApolloLink(
operation =>
new Observable(observer => {
console.log(operation);
observer.error('Should not be here');
}),
),
cache: new InMemoryCache(),
};
}

@NgModule({
imports: [CommonModule, LoonaModule.forRoot()],
exports: [ApolloModule, LoonaModule],
providers: [
{
provide: LOONA_CACHE,
useFactory() {
return new InMemoryCache();
},
},
{
provide: APOLLO_OPTIONS,
useFactory: apolloFactory,
deps: [LoonaLink, LOONA_CACHE],
},
],
})
export class GraphQLModule {
constructor(actions: Actions, loona: Loona) {
actions.subscribe(action => {
console.log('scanned', action);
// loona.dispatch({type: 'test'});
});
}
}
8 changes: 4 additions & 4 deletions examples/angular/lazy/src/app/notes/notes.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import gql from 'graphql-tag';

export class AddNote {
static mutation = gql`
mutation addNote($text: String!) @client {
addNote(text: $text)
mutation addNote($text: String!) {
addNote(text: $text) @client
}
`;

Expand All @@ -15,8 +15,8 @@ export class AddNote {
}

export const allNotes = gql`
query allNotes @client {
notes {
query allNotes {
notes @client {
id
text
}
Expand Down
25 changes: 11 additions & 14 deletions examples/angular/todos/src/app/graphql.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,31 @@ import {CommonModule} from '@angular/common';
import {ApolloClientOptions} from 'apollo-client';
import {ApolloModule, APOLLO_OPTIONS} from 'apollo-angular';
import {InMemoryCache} from 'apollo-cache-inmemory';
import {LoonaModule, LoonaLink, LOONA_CACHE} from '@loona/angular';
import {LoonaModule} from '@loona/angular';

import {TodosState} from './todos/todos.state';
import {ApolloLink, Observable} from 'apollo-link';

export function apolloFactory(
loonaLink: LoonaLink,
cache: InMemoryCache,
): ApolloClientOptions<any> {
export function apolloFactory(): ApolloClientOptions<any> {
return {
link: loonaLink,
cache,
link: new ApolloLink(
operation =>
new Observable(observer => {
console.log(operation);
observer.error('Should not be here');
}),
),
cache: new InMemoryCache(),
};
}

@NgModule({
imports: [CommonModule, LoonaModule.forRoot([TodosState])],
exports: [ApolloModule, LoonaModule],
providers: [
{
provide: LOONA_CACHE,
useFactory() {
return new InMemoryCache();
},
},
{
provide: APOLLO_OPTIONS,
useFactory: apolloFactory,
deps: [LoonaLink, LOONA_CACHE],
},
],
})
Expand Down
1 change: 1 addition & 0 deletions examples/react/basic/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SKIP_PREFLIGHT_CHECK=true
30 changes: 18 additions & 12 deletions examples/react/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@
"private": true,
"dependencies": {
"@loona/react": "1.0.0",
"@material-ui/core": "3.1.0",
"@material-ui/icons": "3.0.1",
"apollo-cache-inmemory": "1.3.12",
"apollo-client": "2.4.8",
"graphql": "14.0.2",
"graphql-tag": "2.10.0",
"react": "16.7.0",
"react-apollo": "2.3.3",
"react-dom": "16.7.0",
"react-scripts": "1.1.5"
"@material-ui/core": "3.9.2",
"@material-ui/icons": "3.0.2",
"apollo-cache-inmemory": "1.5.1",
"apollo-client": "2.5.1",
"graphql": "14.1.1",
"graphql-tag": "2.10.1",
"react": "16.8.03",
"react-apollo": "2.5.1",
"react-dom": "16.8.3",
"react-scripts": "2.1.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build"
}
}
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
12 changes: 5 additions & 7 deletions examples/react/basic/src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import React from 'react';
import {LoonaProvider, createLoona} from '@loona/react';
import {LoonaProvider} from '@loona/react';
import {ApolloClient} from 'apollo-client';
import {InMemoryCache} from 'apollo-cache-inmemory';
import {ApolloProvider} from 'react-apollo';
import {ApolloLink} from 'apollo-link';

import {Root} from './Root';
import {states} from './states';

const cache = new InMemoryCache();

const loona = createLoona(cache);
const client = new ApolloClient({
link: loona,
cache,
link: new ApolloLink(),
cache: new InMemoryCache(),
});

export class App extends React.Component {
render() {
return (
<ApolloProvider client={client}>
<LoonaProvider loona={loona} states={states}>
<LoonaProvider states={states}>
<Root />
</LoonaProvider>
</ApolloProvider>
Expand Down
12 changes: 6 additions & 6 deletions examples/react/basic/src/books/books.state.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import gql from 'graphql-tag';

export class AddBook {
static mutation = gql`
mutation addBook($title: String!) @client {
addBook(title: $title)
mutation addBook($title: String!) {
addBook(title: $title) @client
}
`;

Expand All @@ -19,17 +19,17 @@ export class AddBook {
// GraphQL

export const allBooks = gql`
query allBooks @client {
books {
query allBooks {
books @client {
id
title
}
}
`;

export const recentBook = gql`
query recentBook @client {
recentBook {
query recentBook {
recentBook @client {
id
title
}
Expand Down
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
globals: {
'ts-jest': {
tsConfig: 'tsconfig.test.json',
},
},
transform: {
'^.+\\.ts$': 'ts-jest',
},
testMatch: ['**/tests/**/*.+(spec.ts)'],
moduleFileExtensions: ['ts', 'js']
};
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,5 @@
"path": "./packages/react/build/loona.react.umd.min.js",
"maxSize": "2 kB"
}
],
"resolutions": {
"jest": "23.6.0",
"webpack-dev-server": "3.1.9"
}
]
}
6 changes: 6 additions & 0 deletions packages/angular/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const config = require('../../jest.config');

module.exports = {
...config,
setupFiles: ['<rootDir>/tests/_setup.ts'],
};
24 changes: 2 additions & 22 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
"release:canary": "yarn build && npm publish build --tag canary"
},
"peerDependencies": {
"@angular/core": "^6.1.0 && ^7.0.0",
"@angular/core": "^6.1.0 || ^7.0.0",
"apollo-angular": "^1.3.0",
"apollo-client": "^2.3.0",
"apollo-client": "^2.5.0",
"apollo-cache": "^1.0.0",
"apollo-link": "^1.0.0",
"graphql": "^0.13.2 || ^14.0.0",
Expand Down Expand Up @@ -69,25 +69,5 @@
"typescript": "3.2.4",
"zone.js": "0.8.29",
"apollo-link": "1.2.9"
},
"jest": {
"globals": {
"ts-jest": {
"tsConfig": "tsconfig.test.json"
}
},
"transform": {
"^.+\\.ts$": "ts-jest"
},
"testMatch": [
"**/tests/**/*.+(spec.ts)"
],
"moduleFileExtensions": [
"ts",
"js"
],
"setupFiles": [
"<rootDir>/tests/_setup.ts"
]
}
}
Loading