简体   繁体   English

在同一个 .gql 文件中使用多个查询时出现 Vetur 错误

[英]Vetur error when using multiple queries in same .gql file

I am using Vue typeScript with GraphQL.我在 GraphQL 中使用 Vue typeScript。 Whenever I try to use a query using deconstructor I get an error from Vetur.每当我尝试使用解构器使用查询时,我都会收到来自 Vetur 的错误消息。 I am able to use GetPostData query in the Vue Component and its working fine.我能够在 Vue 组件中使用 GetPostData 查询并且它工作正常。

Trying to use this - https://github.com/apollographql/graphql-tag#support-for-multiple-operations尝试使用这个 - https://github.com/apollographql/graphql-tag#support-for-multiple-operations

在此处输入图片说明

Vue File Vue文件

import { GetPostData } from "../../util/queries/getPageData.gql";

getPageData.gql获取页面数据.gql

query GetPostData {
  continents {
    code
  }
}
query GetCountries($code: String!) {
  country(code: $code) {
    code
  }
}

Vue.config.js Vue.config.js

const antdTheme = require("./src/theme.js");

module.exports = {
  publicPath: "/",
  pwa: {
    iconPaths: {
      favicon32: "./favicon.png",
      favicon16: "./favicon.png",
      appleTouchIcon: "./favicon.png",
      maskIcon: "./favicon.png",
      msTileImage: "./favicon.png"
    }
  },
  css: {
    loaderOptions: {
      less: {
        modifyVars: antdTheme,
        javascriptEnabled: true
      }
    }
  },
  chainWebpack: config => {
    // GraphQL Loader
    config.module
      .rule("graphql")
      .test(/\.(graphql|gql)$/)
      .use("graphql-tag/loader")
      .loader("graphql-tag/loader")
      .end();
  }
};

I think it states that's what you can do but I don't think you really can.我认为它表明这是你可以做的,但我不认为你真的可以。 It's better to put all your queries in a javascript file and import 'graphql-tag' to store queries instead of using a .gql file.最好将所有查询放在一个 javascript 文件中并导入 'graphql-tag' 来存储查询,而不是使用 .gql 文件。

Just tested and Vetur didn't complain, could have been a bug that is already fixed.刚刚测试,Vetur 没有抱怨,可能是一个已经修复的错误。

According to graphql-tag package this case is supported ( docs ), so if Vetur complains must be an issue with the extension itself.根据 graphql-tag 包,这种情况得到支持( docs ),所以如果 Vetur 抱怨一定是扩展本身的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Vetur 将 .vue 文件的第一行标记为错误 - Vetur marks first line of .vue file as an error Go 使用 VSCODE + VETUR 在同一个文件中定义不起作用 - Go To definition does not work in same file with VSCODE + VETUR Vetur 说在模板上使用道具时道具不存在于类型“从不”上 - Vetur says prop doesn't exist on type "never" when using a prop on template 使用 Apollo 在 TypeScript 中填充常量时,对象的类型为“未知”.Vetur(2571) - Object is of type 'unknown'.Vetur(2571) when populating a constant in TypeScript using Apollo VSCode没有将双引号更改为单引号<template>使用 Vetur 和 Prettier 以及 Vue-Cli 3 时</template> - VSCode not changing double quotes to single quotes in <template> when using Vetur and Prettier and Vue-Cli 3 查找 tsconfig.json 或 jsconfig.json 时出现 Vetur 错误 - Vetur error with finding tsconfig.json or jsconfig.json 多个查询,在同一个div中显示结果 - Multiple Queries, show result in same div 文件名与仅在casing.Vetur(1149)中已包含的文件名不同 - File name differs from already included file name only in casing.Vetur(1149) 当“@”用于打字稿类组件模板中的事件绑定时,Vetur 无法正确读取函数名称 - Vetur is not reading the function name correctly when '@' is used for event binding in template of a typescript class component 使用laravel和vue js上传多个文件时无法打印 - Multiple file upload using laravel and vue js error not print
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM