
Product
Unify Your Security Stack with Socket Basics
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.
@teamnovu/vite-plugin-vue-gql-statamic
Advanced tools
A Vite plugin to write GraphQL queries for Statamic inside Vue components.
A Vite plugin to write GraphQL queries for Statamic inside Vue components.
Note Although this plugin is meant to be used with nuxt-graphql-client and Statamic, it does not depend on either of them.
Writing GraphQL queries from scratch in separate files is a pain. This plugin allows you to write GraphQL queries directly inside your Vue components, while preserving proper syntax highlighting.
Additionally, it allows you to couple the individual types from your GraphQL schema with their respective Vue component.
For more detailed information on the idea behind this plugin, please read through teamnovu's use case.
Install the plugin using your package manager of choice:
pnpm i -D @teamnovu/vite-plugin-vue-gql-statamic
Register the plugin in your vite.config.ts
:
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import VueGqlStatamic from '@teamnovu/vite-plugin-vue-gql-statamic'
export default defineConfig({
plugins: [
Vue(),
VueGqlStatamic(),
],
})
Instead of registering the plugin in your vite.config.ts
, you need to register it in your nuxt.config.ts
:
import VueGqlStatamic from '@teamnovu/vite-plugin-vue-gql-statamic'
export default defineNuxtConfig({
vite: {
plugins: [
VueGqlStatamic(),
],
},
})
VueGqlStatamic({
/**
* Path to write the generated .gql-files to.
* @type {string}
*/
generateTo: 'queries/generated',
/**
* Set to true if you do not want any .gql-files to be generated.
* @type {boolean}
*/
disableGqlFileGeneration: false,
/**
* Path to import global fragments from.
* These fragments with be prepended to every generated .gql-file.
* @type {string|false}
*/
importFragmentsFrom: 'queries/fragments',
/**
* GraphQL host to fetch the schema from.
* @type {string}
*/
gqlHost: 'http://localhost/graphql',
/**
* Enables debug logging.
* @type {boolean}
*/
debug: false,
/**
* Generates a human readable output.
* @type {boolean}
*/
pretty: true,
})
A GraphQL query can be written inside a Vue component by using the gql
tag:
<template><!-- ... --></template>
<gql lang="gql">
query MyQuery($uri: String!) {
entry(uri: $uri) {
id
title
}
}
</gql>
<script><!-- ... --></script>
For every gql
tag with the query
attribute (defaults to query
if no attribute is provided), a file will be generated output directory.
By default, the file generated will be named after the component's filename, but you can specify a custom name:
<gql lang="gql" query="my-query">
<!-- ... -->
</gql>
In our case, the plugin is meant to be used in conjunction with nuxt-graphql-client. The plugin will write the GraphQL queries to files, which are then picked up by the GraphQL client.
Usually, we would use the plugin in a project which consumes the GraphQL API provided by Statamic.
There, we would have various blueprints which include a components
field of type replicator, bard or grid.
The sets of this components
replicator would all relate to a specific Vue component.
This allows our editors to create highly dynamic pages by adding and removing isolated components.
In order to not have to write a gigantic GraphQL query, we added support for blueprints and components to this plugin.
This means, we would create a Vue components for every blueprint with a <gql blueprint>
tag and a Vue component for every component with a <gql component>
tag.
Based on our GraphQL-API's schema, this generates fragments for the respective types, which can then be used in the main query.
If you are interested in more details on how we use this plugin, feel free to contact us at developers@novu.ch.
Note Please make sure to read the Contributing Guide before making a pull request.
query
if no attribute is specified..gql
-file to prevent it showing up in git as newly changed all the time.disableGqlFileGeneration
-flag to be able to disable .gql
-file generation while still having the plugin remove all gql
tags..gql
-file with "global" fragments to the top of every query..gql
-files in a directory to the top of every query.nuxt-graphql-client
fails, if no .gql
-files are present (e.g. generate dummy query initially). => https://github.com/Diizzayy/nuxt-graphql-client/issues/315nuxt-graphql-client
from failing.pnpm run dev
is started with an already invalid .gql
-file. This is an issue of the nuxt-graphql-client
-module. Perhaps, this can be fixed, if errors for invalid properties are thrown by this plugin. => https://github.com/Diizzayy/nuxt-graphql-client/issues/315component="BardText"
.npx
commandgql
tags in a single component.
FAQs
A Vite plugin to write GraphQL queries for Statamic inside Vue components.
We found that @teamnovu/vite-plugin-vue-gql-statamic demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.
Product
Socket is launching experimental protection for the Hugging Face ecosystem, scanning for malware and malicious payload injections inside model files to prevent silent AI supply chain attacks.
Research
/Security News
The Socket Threat Research Team uncovered a coordinated campaign that floods the Chrome Web Store with 131 rebranded clones of a WhatsApp Web automation extension to spam Brazilian users.