-
Notifications
You must be signed in to change notification settings - Fork 6
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
Apollo client with options (specifically Fetch authorization) #5
Comments
In a real project, configuration would not really come from In this particular project this would be done here because I used the template https://github.com/PierBover/vuex-apollo-example-project/blob/master/webpack.config.js#L55-L58 When using Vue CLI with the Then webpack creates the vars on your application using DefinePlugin , and you can finally in your code do something like |
Maybe I should have been more specific. Using the DefinePlugin is well and good for things that are environment specific, but per the example above, the Apollo network interface is created with an |
It really depends on how you are doing auth. I've been doing auth via REST for GraphQL projects. Once I have the token I init Apollo Client. This worked for me since all my endpoints are private, but it would not work as a general approach since many APIs have public and private endpoints. As per the docs it's possible to use different middlewares: Maybe the solution is to use |
Right, but doesn't that put us right back at my original post? How would you structure your imports to pass necessary vars to your apollo client (networkInterface)? Differently than I did above? Any thoughts on making the apollo client globally accessible as I did above (eg. |
Personally I would just create an Apollo module with an Something like this: let apolloClient;
export default {
init(config){
// init Apollo here
apolloClient = new ApolloClient(...)
},
apolloClient
} (This is of course a simplification)
With Again, just use You can resolve paths automatically (no need to use resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'@': resolve('src'),
vue: 'vue/dist/vue.js'
},
modules: [ path.resolve('./src/components'), path.resolve('./src'), 'node_modules']
}, |
Echoing the sentiment that making Apollo requests within the component is not a practice that scales to larger applications (likely using Vuex, or some other state management).
One thing I noticed about your example though, is that it instantiates the Apollo client without the ability for
main.js
to pass options into the client.Curious to hear your take on this, but my solution was to make the client globally accessible:
Thoughts?
The text was updated successfully, but these errors were encountered: