-
Notifications
You must be signed in to change notification settings - Fork 52
added apolloClient option for passing a preconfigured client #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you very much for your contribution! :) I just have three things, we should change:
const options = {
apolloClient: (context) => {
return ...;
}
};
|
What if we change this to adding a |
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
|
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 |
…lo_client_option # Conflicts: # dist/vuex-orm-graphql.es5.js # dist/vuex-orm-graphql.es5.js.map # dist/vuex-orm-graphql.umd.js # dist/vuex-orm-graphql.umd.js.map
# dist/vuex-orm-graphql.es5.js # dist/vuex-orm-graphql.es5.js.map # dist/vuex-orm-graphql.umd.js # dist/vuex-orm-graphql.umd.js.map
@phortx 👍 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.