【发布时间】: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