[Vuejs]-Import GraphQL file in nuxt.js

-1👍

The valueOf method is not appropriate for this purpose. A GraphQL schema document does not provide direct access to its queries, mutations, or subscriptions through a key-value pair access method.

First, ensure you have installed the graphql-tag package in your project:

npm install graphql-tag

Define your queries in schema.gql:

query AllUsers {
  allUsers {
    nodes {
      id
      name
      # other fields...
    }
  }
}

import and use the AllUsers query in your component:

<script setup>
import { useQuery } from "@vue/apollo-composable";
import { loader } from "graphql.macro";

const Schema = loader('@/graphql/schema.gql');

const { result } = useQuery({
  query: Schema.AllUsers
});

// Here, 'result' will contain your fetched data when available.
</script>

Hope this helps!

Leave a comment