【问题标题】:VSCode - custom snippet within gql tag/string within a TS fileVSCode - TS 文件中的 gql 标记/字符串中的自定义片段
【发布时间】:2022-11-12 18:28:19
【问题描述】:

我正在使用 ApolloServer 和 Apollo Subgraphs 在 Graphql 中构建一个 API。我正在用 TS 编写,但为了使用子图功能,我需要用 gql 包装我的模式。 例如。

import { gql } from 'apollo-server-core';

export const typeDefs = gql`
    extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable"])

    type User {
        id: Int!
        firstName: String
        lastName: String
        email: String!
    }
`;

不幸的是,当我尝试为graphql-constraint-directive 添加一些自定义 sn-ps 时,我无法让它们在反引号内工作。有没有办法做到这一点?

目前我有这个 sn-p,我尝试将它添加到 typescript.json sn-p 文件中,但正如我所说,它在反引号中不起作用。

"GraphQL Constraint Directive": {
    "prefix": ["@constraint", "constraint"],
    "body": ["@constraint(${1:format}: ${2:email}$0"]
}

本质上,当我在gql`SDL here`; 中定义输入类型时,我希望能够在每个字段后写下“con”一词,然后能够从自动完成下拉列表中选择 sn-p。

input loginInput {
    email: String! @constraint(format: email)
    password: String!  @constraint(minLength: 9, maxLength: 32)
}

【问题讨论】:

    标签: typescript visual-studio-code graphql vscode-snippets


    【解决方案1】:

    要让您的 sn-ps 显示在反引号中,请尝试更改您的 quickSuggestions 设置。您需要将strings 设置为on,以便建议(包括sn-ps)将自动显示。顺便说一句,您应该能够触发建议/sn-ps 以手动显示Ctrl+空间即使将strings 设置为off

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-19
      • 1970-01-01
      相关资源
      最近更新 更多