Code Monkey home page Code Monkey logo

vue-gql's Introduction

vue-gql

A small and fast GraphQL client for Vue.js.

codecov Build Status Bundle Size

Features

  • ๐Ÿ“ฆ Minimal: Its all you need to query GQL APIs.
  • ๐Ÿฆ Tiny: Very small footprint.
  • ๐Ÿ—„ Caching: Simple and convenient query caching by default.
  • ๐Ÿ’ช TypeScript: Written in Typescript.
  • ๐Ÿ’š Minimal Vue.js Components.

Documentation

You can find the full documentation here

Quick Start

First install vue-gql:

yarn add vue-gql graphql

# or npm

npm install vue-gql graphql --save

Setup the GraphQL client/endpoint:

import Vue from 'vue';
import { withProvider, createClient } from 'vue-gql';
import App from './App.vue'; // Your App Component

const client = createClient({
  url: 'http://localhost:3002/graphql'
});

// Wrap your app component with the provider component.
const AppWithGQL = withProvider(App, client);

new Vue({
  render: h => h(AppWithGQL)
}).$mount('#app');

Now you can use the Query and Mutation components to run queries:

<template>
  <Query query="{ posts { title } }" v-slot="{ data, fetching }">
    <div v-if="fetching">Is Fetching ...</div>
    <div v-else>
      <pre>{{ data }}</pre>
    </div>
  </Query>
</template>

<script>
import { Query } from 'vue-gql';

export default {
  components: {
    Query
  }
};
</script>

You can do a lot more, vue-gql makes frequent tasks such as re-fetching, caching, mutation responses, error handling, subscriptions a breeze. Consult the documentation for more use-cases and examples.

Compatibility

This library relies on the fetch web API to run queries, you can use unfetch (client-side) or node-fetch (server-side) to use as a polyfill.

Examples

SOON

License

MIT

vue-gql's People

Contributors

baianater avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

todun sujitrulz

vue-gql's Issues

[feat] Implement Subscriptions

A Subscription component is needed to fully support the GQL consumption methods.

It might require a different client just for it as it would be implemented with Websockets.

subscriptions-transport-ws subscriptionClient: Observable<ExecutionResult<ExecutionResultDataDefault>> is not assignable to type SubscriptionForwarder

I love this library but I am having trouble getting the Subscription client set up. Here is my code (copied from your docs):

import Vue from 'vue'
import App from './App.vue'
import { createClient } from 'vue-gql';
import { SubscriptionClient } from 'subscriptions-transport-ws';

const subscriptionClient = new SubscriptionClient('ws://localhost:4001/graphql', {});

const client = createClient({
  url: 'http://localhost:4000/graphql',
  subscriptionForwarder: op => subscriptionClient.request(op)
});
Vue.config.productionTip = false

new Vue({
  render: h => h(App),
}).$mount('#app')

When I npm run serve this (with vue-cli) I get Typescript error:

10:3 Type '(op: Operation) => Observable<ExecutionResult<ExecutionResultDataDefault>>' is not assignable to type 'SubscriptionForwarder'.
  Type 'Observable<ExecutionResult<ExecutionResultDataDefault>>' is not assignable to type 'ObservableLike<OperationResult>'.
    Types of property 'subscribe' are incompatible.
      Type '(observer: Observer<ExecutionResult<ExecutionResultDataDefault>>) => { unsubscribe: () => void; }' is not assignable to type '(observer: ObserverLike<OperationResult>) => Unsub'.
        Types of parameters 'observer' and 'observer' are incompatible.
          Type 'ObserverLike<OperationResult>' is not assignable to type 'Observer<ExecutionResult<ExecutionResultDataDefault>>'.
            Types of property 'next' are incompatible.
              Type '(value: OperationResult) => void' is not assignable to type '(value: ExecutionResult<ExecutionResultDataDefault>) => void'.
                Types of parameters 'value' and 'value' are incompatible.
                  Type 'ExecutionResult<ExecutionResultDataDefault>' is not assignable to type 'OperationResult'.                           Property 'data' is optional in type 'ExecutionResult<ExecutionResultDataDefault>' but required in type 'OperationResult'.
     8 | const client = createClient({
     9 |   url: 'http://localhost:4000/graphql',
  > 10 |   subscriptionForwarder: op => subscriptionClient.request(op)
       |   ^
    11 | });
    12 | Vue.config.productionTip = false
    13 |
Version: typescript 3.5.3
Time: 4819ms

package.json:

{
  "name": "foobar",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build"
  },
  "dependencies": {
    "graphql": "^14.5.8",
    "subscriptions-transport-ws": "^0.9.16",
    "vue": "^2.6.10",
    "vue-gql": "^0.2.3"
  },
  "devDependencies": {
    "@vue/cli-plugin-typescript": "^4.1.0",
    "@vue/cli-service": "^4.1.0",
    "typescript": "~3.5.3",
    "vue-template-compiler": "^2.6.10"
  }
}

What am I doing wrong here? ๐Ÿค”

Usage with Composition API

Is this wonderful project still being maintained ?
Also, is support for Composition API planned any time in the future ?

Component Option

Firstly, a really nice library! And approximately 500x smaller than my usual Vue-Apollo setup :)

I was wondering if there are plans, or if it is possible to integrate it into component options, similar to vue apollo - E.g.

<script>
export default {
    apollo: {
        query: ...
...

Rather than using the Query components? And also could you access the client through something like this.$vql?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.