Gathering detailed insights and metrics for @diizzayy/gql
Gathering detailed insights and metrics for @diizzayy/gql
Gathering detailed insights and metrics for @diizzayy/gql
Gathering detailed insights and metrics for @diizzayy/gql
npm install @diizzayy/gql
Typescript
Module System
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
⚡️ Minimal GraphQL Client + Code Generation for Nuxt 3
⚡️ Minimal GraphQL Client + Code Generation for Nuxt 3
1# using yarn 2yarn add @diizzayy/gql 3 4# using npm 5npm install @diizzayy/gql --save
@diizzayy/gql
to the buildModules
section of nuxt.config.ts
Configuration Options1import { defineNuxtConfig } from 'nuxt3' 2 3export default defineNuxtConfig({ 4 buildModules: ['@diizzayy/gql'], 5 6 gql: { 7 // configuration 8 }, 9})
GQL_HOST
to the URL of your GraphQL API1publicRuntimeConfig: { 2 GQL_HOST: 'https://api.spacex.land/graphql' // SpaceX GraphQL API for example 3}
Example using the SpaceX GraphQL API:
./queries/starlink.gql
- This query will for the SpaceX API to retrieve the launches for Starlink missions.
1query launches($sort: String = "launch_year", $order: String = "desc") { 2 launches(sort: $sort, order: $order, find: { mission_name: "Starlink" }) { 3 id 4 details 5 mission_name 6 launch_year 7 launch_success 8 links { 9 article_link 10 flickr_images 11 } 12 rocket { 13 rocket_name 14 rocket_type 15 } 16 } 17}
With autoImport
enabled, the query above can be accessed in the Vue portion of your app by prefixing the Operation name (launches
in this example with the Function Prefix).
The launches
query can be executed as GqlLaunches()
Run yarn dev
for the @diizzayy/gql
module to generate the necessary types and functions.
useGql
composable to execute all your queries / mutations.autoImport
enabled, your queries / mutations are accessible within your app by calling the Operation name prefixed by Function Prefix1<script lang="ts" setup> 2const { data } = await useAsyncData('starlink', () => GqlLaunches({ order: 'desc' })) 3</script>
Your data is now fully-typed based on it's pertinent GraphQL Document.
This module can be configured by adding a gql
section inside your nuxt.config.ts
1import { defineNuxtConfig } from 'nuxt3'
2
3export default defineNuxtConfig({
4 gql: {
5 /**
6 * Prevent codegen from printing to console in dev mode
7 *
8 * @type boolean
9 * @default true
10 */
11 silent: boolean,
12
13 /**
14 * Enable hot reloading for GraphQL documents
15 *
16 * @type boolean
17 * @default true
18 */
19 watch: boolean,
20
21 /**
22 * Auto import functions based on the operation names of your queries & mutations
23 *
24 * @type boolean
25 * @default true
26 */
27 autoImport: boolean,
28
29 /**
30 * Prefix for auto imported functions
31 *
32 * @type string
33 * @default 'Gql'
34 */
35 functionPrefix: string,
36
37 /**
38 * Path to folder(s) containing .gql or .graphql files. Can be omitted,
39 * module will automatically search for GraphQL Documents in the project's root directory.
40 *
41 * @note Useful for mono repos.
42 *
43 * @type string[]
44 * @example ['../shared/queries']
45 * */
46 documentPaths: string[],
47
48 /**
49 * Only generate the types for the operations in your GraphQL documents.
50 * When set to true, only the types needed for your operations will be generated.
51 * When set to false, all types from the GraphQL schema will be generated.
52 *
53 * @type boolean
54 * @default true
55 * */
56 onlyOperationTypes: boolean
57 },
58
59 publicRuntimeConfig: {
60 /**
61 * URL pointing to a GraphQL endpoint
62 *
63 * @type string
64 */
65 GQL_HOST: string,
66 },
67})
No vulnerabilities found.
No security vulnerabilities found.