当前位置: 首页>>代码示例>>Java>>正文


Java BatchedExecutionStrategy类代码示例

本文整理汇总了Java中graphql.execution.batched.BatchedExecutionStrategy的典型用法代码示例。如果您正苦于以下问题:Java BatchedExecutionStrategy类的具体用法?Java BatchedExecutionStrategy怎么用?Java BatchedExecutionStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BatchedExecutionStrategy类属于graphql.execution.batched包,在下文中一共展示了BatchedExecutionStrategy类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getExecutionStrategy

import graphql.execution.batched.BatchedExecutionStrategy; //导入依赖的package包/类
@JsonProperty
public ExecutionStrategy getExecutionStrategy() {
    switch (executionStrategy) {
    case "batched":
        return new BatchedExecutionStrategy();
    case "async_serial":
        return new AsyncSerialExecutionStrategy();
    case "subscription":
        return new SubscriptionExecutionStrategy();
    case "async":
    default:
        return new AsyncExecutionStrategy();
    }
}
 
开发者ID:smoketurner,项目名称:dropwizard-graphql,代码行数:15,代码来源:GraphQLFactory.java

示例2: batchingTest

import graphql.execution.batched.BatchedExecutionStrategy; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void batchingTest() {
    GraphQLSchema schema = new TestSchemaGenerator()
            .withOperationsFromSingleton(new CandidatesService())
            .generate();

    AtomicBoolean runBatched = new AtomicBoolean(false);
    GraphQL batchExe = GraphQLRuntime.newGraphQL(schema).queryExecutionStrategy(new BatchedExecutionStrategy()).build();
    ExecutionResult result;
    result = batchExe.execute(ExecutionInput.newExecutionInput()
            .query("{candidates {educations {startYear}}}")
            .context(runBatched).build());
    assertTrue("Query didn't run in batched mode", runBatched.get());
    assertTrue(result.getErrors().isEmpty());
    assertEquals(3, ((Map<String, List>) result.getData()).get("candidates").size());

    //TODO put this back when/if the ability to expose nested queries as top-level is reintroduced
    /*runBatched.getAndSet(false);
    GraphQL simpleExe = GraphQLRuntime.newGraphQL(schema).build();
    result = simpleExe.execute("{educations(users: [" +
                "{fullName: \"One\"}," +
                "{fullName: \"Two\"}," +
                "{fullName: \"Three\"}" +
            "]) {startYear}}", runBatched);
    assertTrue(result.getErrors().isEmpty());*/
}
 
开发者ID:leangen,项目名称:graphql-spqr,代码行数:28,代码来源:BatchingTest.java

示例3: testQuery

import graphql.execution.batched.BatchedExecutionStrategy; //导入依赖的package包/类
@Test
public void testQuery() throws Exception {
    Injector injector = setup();

    // TODO: Support "schema" type so this is generated too :)
    Map<String, GraphQLType> types =
        injector.getInstance(Key.get(new TypeLiteral<Map<String, GraphQLType>>(){}));
    GraphQLSchema schema = GraphQLSchema.newSchema()
        .query((GraphQLObjectType)types.get("QueryPosts"))
        .mutation((GraphQLObjectType)types.get("MutatePosts"))
        .build(new HashSet<>(types.values()));

    GraphQL graphQL = new GraphQL(schema, new BatchedExecutionStrategy());
    ObjectMapper om = new ObjectMapper();
    om.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);

    // Using GraphQL Mutation:
    ExecutionResult result = graphQL.execute(
        "mutation{createPost(post:{title:\"NEW\" authorId:1}){title}}",
        "authorized-user");
    checkExecutionResult(result);
    assertEquals("{\"createPost\":{\"title\":\"NEW\"}}", om.writeValueAsString(result.getData()));

    // ...or the API:
    MutatePosts mutatePosts = injector.getInstance(MutatePosts.class);
    mutatePosts.createPost(new MutatePosts.CreatePostArgs() {
            public InputPost getPost() {
                return new InputPost.Builder()
                    .withTitle("API")
                    .withAuthorId(2)
                    .build();
            }
        });

    // Using GraphQL Query:
    result = graphQL.execute("{posts{title author{firstName lastName}}}");
    checkExecutionResult(result);

    String value = om.writeValueAsString(result.getData());
    assertEquals("{\"posts\":[{\"author\":{\"firstName\":\"Brian\",\"lastName\":\"Maher\"},\"title\":\"GraphQL Rocks\"},{\"author\":{\"firstName\":\"Rahul\",\"lastName\":\"Singh\"},\"title\":\"Announcing Callisto\"},{\"author\":{\"firstName\":\"Rahul\",\"lastName\":\"Singh\"},\"title\":\"Distelli Contributing to Open Source\"},{\"author\":{\"firstName\":\"Brian\",\"lastName\":\"Maher\"},\"title\":\"NEW\"},{\"author\":{\"firstName\":\"Rahul\",\"lastName\":\"Singh\"},\"title\":\"API\"}]}", value);

    // ...or the API:
    QueryPosts queryPosts = injector.getInstance(QueryPosts.class);
    List<Post> posts = queryPosts.getPosts();
    // ...since we are not using GraphQL, the authors will not be resolved:
    assertEquals(posts.get(0).getAuthor().getClass(), Author.Unresolved.class);
    assertArrayEquals(
        new String[]{"GraphQL Rocks", "Announcing Callisto", "Distelli Contributing to Open Source", "NEW", "API"},
        posts.stream().map((post) -> post.getTitle()).toArray(size -> new String[size]));
    assertArrayEquals(
        new Integer[]{1,2,2,1,2},
        posts.stream().map((post) -> post.getAuthor().getId()).toArray(size -> new Integer[size]));
}
 
开发者ID:Distelli,项目名称:graphql-apigen,代码行数:54,代码来源:PostsTest.java


注:本文中的graphql.execution.batched.BatchedExecutionStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。