Apollo Graphql导入问题与cacheControl指令

Apollo Graphql导入问题与cacheControl指令,graphql,graphql-js,apollo-server,express-graphql,Graphql,Graphql Js,Apollo Server,Express Graphql,我正在使用“graphql导入”:“^0.7.1” 我试图将@cacheControl指令添加到我的graphql架构中 type Post @cacheControl(maxAge: 240) { id: Int! title: String author: Author votes: Int @cacheControl(maxAge: 30) readByCurrentUser: Boolean! @cacheControl(scope: PRIVATE) } 然后它给

我正在使用
“graphql导入”:“^0.7.1”

我试图将
@cacheControl
指令添加到我的graphql架构中

type Post @cacheControl(maxAge: 240) {
  id: Int!
  title: String
  author: Author
  votes: Int @cacheControl(maxAge: 30)
  readByCurrentUser: Boolean! @cacheControl(scope: PRIVATE)
}
然后它给出了这个错误-

Error: Directive cacheControl: Couldn't find type cacheControl in any of the schemas.
Error: There can be only one type named "CacheControlScope".

Enum value "CacheControlScope.PUBLIC" can only be defined once.

Enum value "CacheControlScope.PRIVATE" can only be defined once.
所以在从link得到提示之后-

我添加了下面的代码

directive @cacheControl(
  maxAge: Int,
  scope: CacheControlScope
) on OBJECT | FIELD_DEFINITION

enum CacheControlScope {
  PUBLIC
  PRIVATE
}
但从那以后,我开始犯这个错误-

Error: Directive cacheControl: Couldn't find type cacheControl in any of the schemas.
Error: There can be only one type named "CacheControlScope".

Enum value "CacheControlScope.PUBLIC" can only be defined once.

Enum value "CacheControlScope.PRIVATE" can only be defined once.

我无法找出如何解决此问题。

在哪里声明这些枚举和指令? 我一直收到这些错误,只是因为我将它们放入了一个被多次引用的typedef文件中。 然后,我将这段代码移到了我的主模式文件中

const CacheControl = gql`
    enum CacheControlScope {
        PUBLIC
        PRIVATE
    }

    directive @cacheControl (
        maxAge: Int
        scope: CacheControlScope
    ) on FIELD_DEFINITION | OBJECT | INTERFACE
`
...

const typeDefs = [
    CacheControl,
    ...
]

const server = new ApolloServer({
    typeDefs,
    ...
})

问题解决了。

静态提示也给了我同样的错误,所以我在解析器中尝试了动态提示,效果很好

关于:


也面临这个问题,找不到指令的原因是模式缝合。我使用了与在模式本身中放置指令和枚举定义相同的工作。当我遇到该错误时,我必须升级到至少2.6.6,因为这是他们为dupe错误添加的修复程序,您将获得ref:

您能否尝试将cacheDirective放在directives.graphql上,然后导入它(#从“directives.graphql”导入cacheControl)看看它是否有效?@jgoday我也试过,但仍然不起作用