有没有一种方法可以对vscode中的`(重音符)里面的GraphQl TypeDef进行语法突出显示?

时间:2020-03-11 20:02:22

标签: visual-studio-code graphql

我想语法突出显示typeDef中的代码。有可能吗?

对此有扩展吗?还是我必须以其他方式编码typeDef?

export const typeDef = `
 type User {
  _id: ID!
  email: String!
  password: String
  createdEvents: [Event!]
 }

 type AuthData {
  userId: ID!
  token: String!
  tokenExpiration: Int!
 }

 input UserInput {
  email: String!
  password: String!
 }
`;

2 个答案:

答案 0 :(得分:1)

假设您正在使用right extension,则需要使用gql中的graphql-tag标签。

const gql = require('graphql-tag')

const typeDefs = gql`
  type User { ... }
`

标记解析提供的字符串并返回DocumentNode对象,该对象应传递给makeExecutableSchemaApolloServer构造函数。在客户端,ApolloClient使用的查询也应该是DocumentNode对象,并且应该以相同的方式包装。

该扩展程序能够检测到标记的用法并相应地应用语法突出显示。

答案 1 :(得分:1)

使用 String.raw 欺骗 VSCode 进入语法高亮 GraphQL。它也适用于其他语言。

<div id='form__option3' class="form__option form__option3">
  <input id="Input NameShipper" type="text" class="InputReciever field" />
</div>