Skip to content
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

Replace Apollo Provider after initialization #999

Open
ivansieder opened this issue Jun 9, 2020 · 6 comments
Open

Replace Apollo Provider after initialization #999

ivansieder opened this issue Jun 9, 2020 · 6 comments
Labels

Comments

@ivansieder
Copy link

@ivansieder ivansieder commented Jun 9, 2020

Is your feature request related to a problem? Please describe.
Our Apollo HTTP Link depends on some Vue props being passed down, as we need to add a widget-token to the headers on each request.

Describe the solution you'd like
Either being able to initialize vue-apollo inside the created hook with the appropriate props or simply replacing the http link from within the created hook after the apollo provider has been initialized and installed would be ideal.

@ivansieder
Copy link
Author

@ivansieder ivansieder commented Jun 9, 2020

The "best" (the best among the probably ugliest) solution I was able to find is the one to add the context to the $query property of the apollo component option as a function which seems to execute it each time and allows to access the Vue instance props:

apollo: {
  $query: {
    context() {
      return {
        headers: {
          "Some-Token": `${this.myTokenProp}`
        }
      }
    }
  }
}
@gaoxianglyx
Copy link

@gaoxianglyx gaoxianglyx commented Jul 17, 2020

did you find the solution?

@ivansieder
Copy link
Author

@ivansieder ivansieder commented Jul 17, 2020

@gaoxianglyx for now I've stuck to the solution mentioned above to set the context object, do you have any other ideas?

@Akryum
Copy link
Member

@Akryum Akryum commented Oct 15, 2020

I think using apollo context is the right way to go.

@Akryum Akryum added question and removed enhancement labels Oct 15, 2020
@ivansieder
Copy link
Author

@ivansieder ivansieder commented Oct 15, 2020

@Akryum thank you. Could it be an idea to expose a function to set the context dynamically at runtime? Cause this way we currently have to set the context at each call.

@gaoxianglyx
Copy link

@gaoxianglyx gaoxianglyx commented Oct 18, 2020

@ivansieder I find the right way to set context,here is the example
this.$apollo.query({ query:getXXX, context: { headers: { "token": "token_code", } }, variables: { xxx: 123 } }).then(() => {})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.