Skip to content

Commit 0149c1a

Browse files
committed
More options
1 parent 0f3ad01 commit 0149c1a

File tree

8 files changed

+27
-10
lines changed

8 files changed

+27
-10
lines changed

dist/vuex-orm-apollo.esm.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9836,7 +9836,7 @@ var Context = /** @class */ (function () {
98369836
var originalFieldGenerator = model.baseModel.fields.bind(model.baseModel);
98379837
model.baseModel.fields = function () {
98389838
var originalFields = originalFieldGenerator();
9839-
originalFields['$isPersisted'] = model.baseModel.attr(false);
9839+
originalFields['$isPersisted'] = model.baseModel.boolean(false);
98409840
return originalFields;
98419841
};
98429842
};
@@ -9894,7 +9894,9 @@ var VuexORMApollo = /** @class */ (function () {
98949894
this.setupMethods();
98959895
this.httpLink = new HttpLink({
98969896
uri: options.url ? options.url : '/graphql',
9897-
credentials: 'same-origin'
9897+
credentials: options.credentials ? options.credentials : 'same-origin',
9898+
headers: options.headers ? options.headers : {},
9899+
useGETForQueries: Boolean(options.useGETForQueries)
98989900
});
98999901
this.apolloClient = new ApolloClient({
99009902
link: this.httpLink,

docs/guide/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ After [installing](/guide/setup) this plugin you can load data in your component
6565
/**
6666
* Returns all users with reactivity.
6767
*/
68-
users: () => User.all()
68+
users: () => User.query().withAll().all()
6969
},
7070
7171

docs/guide/fetch/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ author user loaded.
5353
So using the regular Vuex-ORM getters should work out of the box now:
5454

5555
```javascript
56-
const comments = Comment.all();
56+
const comments = Comment.query().withAll().all();
5757
```
5858

5959
When fetching all returned records replace the respective existing records in the Vuex-ORM database.

docs/guide/setup/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ VuexORM.use(VuexORMApollo, { database });
3030
These are the possible options to pass when calling `VuexORM.use()`:
3131

3232
- `database` (required): The Vuex-ORM database.
33-
- `url` (optional, default: `/graphql`): The URL to the graphql api. Will be passed to apollo-client.
3433
- `debug` (optional, default: `false`): Set to true to activate the debug logging.
34+
- `url` (optional, default: `/graphql`): The URL to the graphql api. Will be passed to apollo-client.
35+
- `headers` (optional, default: `{}`) HTTP Headers. See [apollo-link-http])(https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-http#options)
36+
- `credentials` (optional, default: `same-origin`) Credentials Policy. See [apollo-link-http])(https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-http#options)
37+
- `useGETForQueries` (optional, default: `false`) Use GET for queries (not for mutations). See [apollo-link-http])(https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-http#options)
3538

3639
More options will come in future releases.
3740

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@types/graphql": "^0.12.3",
4848
"@types/inflection": "^1.5.28",
4949
"@types/lodash-es": "^4.17.0",
50-
"@vuex-orm/core": "^0.25.0",
50+
"@vuex-orm/core": "^0.25.1",
5151
"apollo-cache-inmemory": "^1.1.7",
5252
"apollo-client": "^2.2.2",
5353
"apollo-link": "^1.2.0",

src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default class Context {
7070
model.baseModel.fields = () => {
7171
const originalFields = originalFieldGenerator();
7272

73-
originalFields['$isPersisted'] = model.baseModel.attr(false);
73+
originalFields['$isPersisted'] = model.baseModel.boolean(false);
7474

7575
return originalFields;
7676
};

src/interfaces.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import ORMModel from '@vuex-orm/core/lib/model/Model';
2+
import Database from '@vuex-orm/core/lib/database/Database';
23

34
export type DispatchFunction = (action: string, data: Data) => Promise<any>;
45

6+
export interface Options {
7+
database: Database;
8+
url?: string;
9+
headers?: { [index: string]: any };
10+
credentials?: string;
11+
useGETForQueries?: boolean;
12+
debug?: boolean;
13+
}
14+
515
export interface ActionParams {
616
commit: any;
717
dispatch: DispatchFunction;

src/vuex-orm-apollo.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Model from './model';
22
import { ApolloClient, FetchPolicy } from 'apollo-client';
33
import { HttpLink } from 'apollo-link-http';
44
import { InMemoryCache } from 'apollo-cache-inmemory';
5-
import { Data, ActionParams, Arguments, DispatchFunction, PatchedModel } from './interfaces';
5+
import { Data, ActionParams, Arguments, DispatchFunction, PatchedModel, Options } from './interfaces';
66
import QueryBuilder from './queryBuilder';
77
import { upcaseFirstLetter } from './utils';
88
import Context from './context';
@@ -26,14 +26,16 @@ export default class VuexORMApollo {
2626
* @param components
2727
* @param options
2828
*/
29-
public constructor (components: Components, options: any) {
29+
public constructor (components: Components, options: Options) {
3030
this.context = new Context(components, options);
3131

3232
this.setupMethods();
3333

3434
this.httpLink = new HttpLink({
3535
uri: options.url ? options.url : '/graphql',
36-
credentials: 'same-origin'
36+
credentials: options.credentials ? options.credentials : 'same-origin',
37+
headers: options.headers ? options.headers : {},
38+
useGETForQueries: Boolean(options.useGETForQueries)
3739
});
3840

3941
this.apolloClient = new ApolloClient({

0 commit comments

Comments
 (0)