question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hello,

I’m working on a GraphQL client called greed that I haven’t open sourced yet. Its framework/library agnostic and wanted to create some vue bindings for it. I want to base the bindings off the same signature that I got working with react which is:

container(
  greed, 
  defaults, 
  queries, 
  mutations
)(component);

// Using a decorator
@container(
  greed, 
  defaults, 
  queries, 
  mutations
)
someComponent

greed: greedInstance- is the greed instance you want to use defaults: ?function - are the default data for the component to render queries: ?function - are the queries you can run when some user input occurs mutations: ?function - are the mutations you can run when some user input occurs component: Component - the component to enhance

The container essentially enhances whatever component it receives with data needed to render and methods that can be executed to run queries and mutations when some user input occurs in the application.

However given that there are different types of templates vs components in vue i’m not sure how to go about injecting/enhancing vue components/templates. I’m not very familiar with vue which is why I wanted some feedback and direction on how best to accomplish this with vue. Any help and guidance would be really appreciated.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
yyx990803commented, Nov 16, 2016

You don’t need to worry about templates at all. The template is basically just the render function.

In Vue, a component is in most cases defined as a plain options object:

export default {
  data () { ... },
  created () { ... },
  computed: { ... },
  methods: { ... }
}

You basically modify/patch this options object in your enhancer function.

Alternatively, Vue plugins can apply a global mixin that injects lifecycle hooks into all components. In the lifecycle hooks you check for a custom options field (e.g. graphql or greed):

const greedPlugin = Vue => {
  Vue.mixin({
    beforeCreate () {
      if (this.$options.greed) {
        // ... initialize stuff
      }
    }
  })
}

Vue.use(greedPlugin)

new Vue({
  greed: {
    queries,
    mutations
  }
})

You can consult vue-rx which is implemented this way.

Closing since this is a question, but you can continue the discussion in this thread.

1reaction
smolinaricommented, Dec 6, 2016

Well, your project sounds interesting. Looking forward to seeing it.

Scott

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue Apollo
Integrate GraphQL in your Vue.js apps! Get Started →. Automatic updates. Don't think about updating the UI or refetching the queries!
Read more >
Getting Started with Vue Apollo
Vue is a modern JavaScript framework for building single-page applications. Apollo Client is a fully-fledged GraphQL client and state management ...
Read more >
Part 1: Why you should use Vue + GraphQL
In practical terms, GraphQL is a way to facilitate the communication between a client and a web server. So you can think of...
Read more >
Course Introduction | GraphQL Vue 3 Apollo Tutorial
A powerful and concise tutorial that will introduce you to GraphQL and integrating GraphQL into your Vue app with Apollo, in the shortest...
Read more >
Apollo Vue: How to Connect to GraphQL APIs in Vue JS
In this tutorial, you will learn how to connect to GraphQL APIs in your Vue application. You will use a really great library...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found