Closed toadkicker closed 5 years ago
Thank you very much for your contribution! :)
I just have three things, we should change:
options.link
option, because it's part of the client.const options = {
apolloClient: (context) => {
return ...;
}
};
What if we change this to adding a clients/DefaultClient
class, similar to how you approached the adapter problem?
This would force the user to write a wrapper class around the ApolloClient, which is too much here I think :)
This is how I'm setting it up in store/index
, I'm not completely clear what you mean with passing context in the option:
import VuexORM from '@vuex-orm/core'
import AWSAppSyncClient from 'aws-appsync'
import { Auth } from 'aws-amplify'
import VuexORMGraphQL from '@vuex-orm/plugin-graphql'
import database from '../database'
import awsexports from '../aws-exports'
const options = {
defaultOptions: {
watchQuery: {
fetchPolicy: 'cache-and-network'
}
},
connectionQueryMode: 'nodes',
database: database,
url: awsexports.aws_appsync_graphqlEndpoint,
includeExtensions: true,
debug: process.env.NODE_ENV !== 'production'
}
const config = {
url: awsexports.aws_appsync_graphqlEndpoint,
region: awsexports.aws_appsync_region,
auth: {
type: awsexports.aws_appsync_authenticationType,
jwtToken: async () => (await Auth.currentSession()).getIdToken().getJwtToken()
}
}
const client = new AWSAppSyncClient(config, options)
options.apolloClient = client
VuexORM.use(VuexORMGraphQL, options)
export const plugins = [
VuexORM.install(database)
]
I'm not completely clear what you mean with passing context in the option:
Oh sorry, I think I didn't make that clear. In your implementation we pass the apollo client into the options as a instance of the client. But to properly setup a client, the developer could need the context. So I want to provide it. We can achieve that by changing how plugin-graphql accepts the client: not as a object, but by calling a function.
So changing your code how to setup a client it would work like this:
import VuexORM from '@vuex-orm/core'
import AWSAppSyncClient from 'aws-appsync'
import { Auth } from 'aws-amplify'
import VuexORMGraphQL from '@vuex-orm/plugin-graphql'
import database from '../database'
import awsexports from '../aws-exports'
const options = {
defaultOptions: {
watchQuery: {
fetchPolicy: 'cache-and-network'
}
},
connectionQueryMode: 'nodes',
database: database,
url: awsexports.aws_appsync_graphqlEndpoint,
includeExtensions: true,
debug: process.env.NODE_ENV !== 'production'
}
// I changed this!
options.apolloClient =(contex) => {
const config = {
url: awsexports.aws_appsync_graphqlEndpoint,
region: awsexports.aws_appsync_region,
auth: {
type: awsexports.aws_appsync_authenticationType,
jwtToken: async () => (await Auth.currentSession()).getIdToken().getJwtToken()
}
};
return new AWSAppSyncClient(config, options);
};
VuexORM.use(VuexORMGraphQL, options)
export const plugins = [
VuexORM.install(database)
]
Also I think we then can drop the support for options.link
completly
@phortx :+1: merge ready
Looks good :) Thank you very much for your contribution!
This adds
context.options.apolloClient
to the available options so that developers can instantiate their own client and pass it to the plugin.