简体   繁体   English

在 Apollo 中查找缺失的 GraphQL 解析器

[英]Find Missing GraphQL Resolvers in Apollo

Using apollo-server , if I attempt to define a graphql resolver that does not exist in my schema, the computer yells at me.使用apollo-server ,如果我尝试定义一个在我的架构中不存在的 graphql 解析器,计算机就会对我大喊大叫。

[Error: Query.foo defined in resolvers, but not in schema] [错误:Query.foo 在解析器中定义,但不在架构中]

This is good!这很好!

Is it possible, using the apollo (or other?) tools, to do the opposite?是否有可能使用阿波罗(或其他?)工具来做相反的事情? That is, is there a way to have apollo tell me if there's a query, mutation, or subscription operation that's defined in my schema but not defined in my resolvers?也就是说,有没有办法已经阿波罗告诉我,如果有一个查询,突变,或订阅,在我的架构中定义的,但在我的解析器未定义操作?

There's an optional resolverValidationOptions object that can be passed to makeExecutableSchema to enforce some additional resolver validations as shown here :还有一个可选的resolverValidationOptions可以传递到目标makeExecutableSchema执行一些额外的解析器验证如图所示在这里

  • requireResolversForArgs will cause makeExecutableSchema to throw an error if no resolve function is defined for a field that has arguments.如果没有为具有参数的字段定义解析函数, requireResolversForArgs将导致makeExecutableSchema抛出错误。
  • requireResolversForNonScalar will cause makeExecutableSchema to throw an error if a non-scalar field has no resolver defined.如果非标量字段没有定义解析器, requireResolversForNonScalar将导致makeExecutableSchema抛出错误。 Setting this to true can be helpful in catching errors, but defaults to false to avoid confusing behavior for those coming from other GraphQL libraries.将此设置为true有助于捕获错误,但默认设置为 false 以避免混淆来自其他 GraphQL 库的行为。
  • requireResolversForAllFields asserts that all fields have a valid resolve function. requireResolversForAllFields断言所有字段都有一个有效的解析函数。
  • requireResolversForResolveType will require a resolveType() method for Interface and Union types. requireResolversForResolveType将需要一个用于接口和联合类型的resolveType()方法。 This can be passed in with the field resolvers as __resolveType().这可以通过字段解析器作为 __resolveType() 传入。 False to disable the warning. False 禁用警告。
  • allowResolversNotInSchema turns off the functionality which throws errors when resolvers are found which are not present in the schema. allowResolversNotInSchema关闭在找到不存在于架构中的解析器时引发错误的功能。 Defaults to false , to help catch common errors.默认为false ,以帮助捕获常见错误。

None of them specifically targets only fields on the root types, but you may be able to make use of one or more.他们没有专门针对在根类型的字段,但是你可以利用一个或多个。

These options are not exposed directly through ApolloServer, but you can always do:这些选项不会直接通过 ApolloServer 公开,但您始终可以这样做:

const schema = makeExecutableSchema({ typeDefs, resolvers, resolverValidationOptions })
const apollo = new ApolloServer({ schema })

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM