logaretm / villus

🏎 A tiny and fast GraphQL client for Vue.js
https://villus.dev
MIT License
791 stars 31 forks source link

Setup ? #126

Closed bobmcallan closed 3 years ago

bobmcallan commented 3 years ago

I'm using Vue 3, and have to connect to 2 Gql servers (private/public). The server information and token is only available post login and hence the application is loaded before I know the gql details.

Therefore this does not work as I do not know the url at start up. // Your App component export default { setup() { useClient({ url: '/graphql', // your endpoint. }); }, };

Is is possible to load the client in the #app (url:null), and then load once I've pulled the details from the server. Either in the page component or ?

Thanks. Bob

logaretm commented 3 years ago

Sorry for taking long to reply to this, at the moment villus doesn't allow changing the URL once initialized. as the url property is marked as private.

But, you could create a custom plugin that ensures the URL is correctly set before executing the query:

export const clientUrl = ref('#url');

function urlPlugin({ opContext }) {
  opContext.url = clientUrl.value;
}

Then you can update the clientUrl from anywhere in the app like after when you've fetched the user data.