All Projects → jacobclevenger → Vite Plugin Vue Gql

jacobclevenger / Vite Plugin Vue Gql

Licence: mit
⚡ GraphQL Tags for your Vue SFC ⚡

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Vite Plugin Vue Gql

Ever
Ever® - Open-Source Commerce Platform for On-Demand Economy and Digital Marketplaces
Stars: ✭ 980 (+2350%)
Mutual labels:  graphql
Ultimate Backend
Multi tenant SaaS starter kit with cqrs graphql microservice architecture, apollo federation, event source and authentication
Stars: ✭ 978 (+2345%)
Mutual labels:  graphql
Manifold
Manifold plugs into Java to supplement it with powerful features, from Type-safe Metaprogramming (direct access to GraphQL, JSON, XML, etc.), Extension Methods, Operator Overloading, and Unit Expressions to an integrated Template Engine and a Preprocessor. All fully supported in IntelliJ IDEA and Android Studio. Simply add Manifold to your project and begin taking advantage of it.
Stars: ✭ 993 (+2382.5%)
Mutual labels:  graphql
Ggql
GraphQL implementation for golang.
Stars: ✭ 37 (-7.5%)
Mutual labels:  graphql
Graphqldockerproxy
A generic Graphql API for Docker and Kubernetes
Stars: ✭ 38 (-5%)
Mutual labels:  graphql
Crypto Grommet
Crypto and equities app
Stars: ✭ 39 (-2.5%)
Mutual labels:  graphql
Zf Doctrine Graphql
GraphQL for Doctrine using Hydrators
Stars: ✭ 36 (-10%)
Mutual labels:  graphql
Fullstack Tutorial
🚀 The Apollo platform tutorial app
Stars: ✭ 1,007 (+2417.5%)
Mutual labels:  graphql
Asp.net Core Graphql Middleware
ASP.Net Core GraphQL Middleware
Stars: ✭ 38 (-5%)
Mutual labels:  graphql
React Apollo Decorators
Better decorators for Apollo and React
Stars: ✭ 39 (-2.5%)
Mutual labels:  graphql
Glutenproject.com
Google for Certified Gluten Free Products
Stars: ✭ 37 (-7.5%)
Mutual labels:  graphql
Timbuctoo
an RDF datastore that gives researchers control over the sharing of data between datasets
Stars: ✭ 37 (-7.5%)
Mutual labels:  graphql
Persistgraphql Webpack Plugin
PersistGraphQL Webpack Plugin
Stars: ✭ 39 (-2.5%)
Mutual labels:  graphql
Graphql Rust Demo
GraphQL Rust Demo
Stars: ✭ 37 (-7.5%)
Mutual labels:  graphql
Level
Team communication optimized for deep work
Stars: ✭ 1,005 (+2412.5%)
Mutual labels:  graphql
Vuewp
WordPress Vuejs GraphQL
Stars: ✭ 36 (-10%)
Mutual labels:  graphql
React Boilerplate
⚛ The stable base upon which we build our React projects at Mirego.
Stars: ✭ 39 (-2.5%)
Mutual labels:  graphql
Twitter Clone Graphql Backend
A Simple CRUD using GraphQL
Stars: ✭ 42 (+5%)
Mutual labels:  graphql
Graphql Lodash
🛠 Data manipulation for GraphQL queries with lodash syntax
Stars: ✭ 1,003 (+2407.5%)
Mutual labels:  graphql
Niklick
Rails Versioned API solution template for hipsters! (Ruby, Ruby on Rails, REST API, GraphQL, Docker, RSpec, Devise, Postgress DB)
Stars: ✭ 39 (-2.5%)
Mutual labels:  graphql

VQL

Clean up your Vue SFC Scripts by moving your graphql quieres to their own block

NPM version

Why?

When writing Vue clients for GraphQL APIs, I've noticed scripts in Vue SFC files have become over-filled with GraphQL queries and had a need to organize the code better without taking away from what makes SFCs great: Having all the code for a single component organized and in one place.

Moving queries to their own files would then create multiple files for a single component, cluttering the project more and reducing productivity in having to write components spanning multiple files.

Enter Vue GQL! I wrote this Vite plugin to allow placing GraphQL queries related to a component directly within the component file without cluttering scripts, by placing them within their own specialized <gql> tags.

⚠️ This Plugin is still in Development and currently only works with the <script setup> format

Install

# Install Plugin
npm i -D vite-plugin-vue-gql

# Install Peer Dependicies
npm i @urql/vue graphql
// vite.config.ts

import Vue from '@vitejs/plugin-vue'
import Vql from 'vite-plugin-vue-gql'

export default {
  plugins: [
    Vue(), 
    Vql()
  ],
}

If you are using typescript, make sure you include the following in your tsconfig.json

{
  "compilerOptions": {
    "types": [
      "vite-plugin-vue-gql/client"
    ]
  }
}

Usage

Instead of import your functions from @urql/vue you should now import them from the vql package.

import { useQuery, useMutation, useSubscription } from 'vql'

<gql> tags can have the following attributes, query(not required), mutation, subscription, and name. The first three attributes indicates what type of query it is while the name attribute allows you to have multiple queries in the same Vue SFC.

<!-- Query-->
<gql></gql>

<!-- Mutation -->
<gql mutation></gql>

<!-- Subscription -->
<gql subscription></gql>

<!-- Named GQL Block -->
<gql name="users"></gql>

Examples

Basic Usage

<script setup lang="ts">
import { useQuery } from 'vql'

const { data } = useQuery()
</script>

<template>
  <h1>{{ data.hello }}</h1>
</template>

<gql>
{
  hello
}
</gql>

Query with Variables

<script setup lang="ts">
import { ref } from 'vue'
import { useQuery } from 'vql'

const name = ref('Evan')
const { data } = useQuery({ name })
</script>

<template>...</template>

<gql>
query($name: String!) {
  user(name: $name) {
    username
  }
}
</gql>

Named Query

<script setup lang="ts">
import { ref } from 'vue'
import { useQuery } from 'vql'

const name = ref('Evan')
const { data } = useQuery('users', { name })
</script>

<template>...</template>

<gql name="users">
query($name: String!) {
  user(name: $name) {
    username
  }
}
</gql>

Mutations

<script setup lang="ts">
import { ref } from 'vue'
import { useMutation } from 'vql'

const { executeMutation } = useMutation()
</script>

<template>...</template>

<gql mutation>
mutation($name: String!) {
  createUser(name: $name) {
    username
  }
}
</gql>

Subscriptions

<script setup lang="ts">
import { ref } from 'vue'
import { useSubscription } from 'vql'

const isPaused = ref(false)
const handleSubscription = (messages = [], response) => {
  return [response.newMessages, ...messages]
}

const { data } = useSubscription({ from: 'Eren' }, { pause: isPaused }, handleSubscription)
</script>

<template>...</template>

<gql mutation>
subscription MessageSub($from: String!) {
  newMessages(from: $from) {
    id
    from
    text
  }
}
</gql>

Roadmap

  • [ ] Add support for fragments
  • [ ] Investigate automatically generating queries from SFC templates

License

MIT License © 2021-PRESENT Jacob Clevenger

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].