GraphQL 模式生成
GraphQL schema generation
我正在使用 java 注释生成 graphQL 模式。感谢 graphql-spqr library。我正在将代码调用到
GraphQLSchemaGenerator schemaGenerator = new GraphQLSchemaGenerator()
.withResolverBuilders(new AnnotatedResolverBuilder())
.withValueMapperFactory(new JacksonValueMapperFactory())
.withOperationsFromSingleton(<annotatedClassObject>);
GraphQLSchema schema = schemaGenerator.generate();
每次调用 graphQL 都会执行以上代码 API。我知道 GraphQL Java 库记录了以下行。
/** Building this object is very cheap and can be done on each
* execution * if necessary. Building the schema is often not
* as cheap, especially if its parsed from graphql IDL schema
* format via {@link graphql.schema.idl.SchemaParser}.
*/
有什么方法可以收集有关生成此模式的每次调用需要多长时间的指标?
我是 graphql-spqr 的作者。我可以告诉您的是,您绝对应该 而不是 为每个请求调用它。 graphql-java 文档指的是 GraphQL
对象,它的构造确实很便宜,但模式却不是。 SPQR 在生成模式时会扫描整个 class 层次结构,这在一般情况下相当昂贵。
您的具体用例是什么?为什么要在每次调用时构建一个新的模式实例?无论您想要实现什么 - 几乎肯定有更好的方法。
至于测量时间,您可以使用JMH(Java Microbenchmark Harness)。
我正在使用 java 注释生成 graphQL 模式。感谢 graphql-spqr library。我正在将代码调用到
GraphQLSchemaGenerator schemaGenerator = new GraphQLSchemaGenerator()
.withResolverBuilders(new AnnotatedResolverBuilder())
.withValueMapperFactory(new JacksonValueMapperFactory())
.withOperationsFromSingleton(<annotatedClassObject>);
GraphQLSchema schema = schemaGenerator.generate();
每次调用 graphQL 都会执行以上代码 API。我知道 GraphQL Java 库记录了以下行。
/** Building this object is very cheap and can be done on each
* execution * if necessary. Building the schema is often not
* as cheap, especially if its parsed from graphql IDL schema
* format via {@link graphql.schema.idl.SchemaParser}.
*/
有什么方法可以收集有关生成此模式的每次调用需要多长时间的指标?
我是 graphql-spqr 的作者。我可以告诉您的是,您绝对应该 而不是 为每个请求调用它。 graphql-java 文档指的是 GraphQL
对象,它的构造确实很便宜,但模式却不是。 SPQR 在生成模式时会扫描整个 class 层次结构,这在一般情况下相当昂贵。
您的具体用例是什么?为什么要在每次调用时构建一个新的模式实例?无论您想要实现什么 - 几乎肯定有更好的方法。
至于测量时间,您可以使用JMH(Java Microbenchmark Harness)。