graphql.GraphQL.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(189)

本文整理了Java中graphql.GraphQL.<init>()方法的一些代码示例,展示了GraphQL.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GraphQL.<init>()方法的具体详情如下:
包路径:graphql.GraphQL
类名称:GraphQL
方法名:<init>

GraphQL.<init>介绍

[英]A GraphQL object ready to execute queries
[中]准备执行查询的GraphQL对象

代码示例

代码示例来源:origin: graphql-java/graphql-java

public GraphQL build() {
    assertNotNull(graphQLSchema, "graphQLSchema must be non null");
    assertNotNull(queryExecutionStrategy, "queryStrategy must be non null");
    assertNotNull(idProvider, "idProvider must be non null");
    return new GraphQL(graphQLSchema, queryExecutionStrategy, mutationExecutionStrategy, subscriptionExecutionStrategy, idProvider, instrumentation, preparsedDocumentProvider);
  }
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

serviceCodes = graph.serviceCodes;
this.graph = graph;
graphQL = new GraphQL(
    new IndexGraphQLSchema(this).indexSchema,
    new ExecutorServiceExecutionStrategy(Executors.newCachedThreadPool(

代码示例来源:origin: org.objectstyle.graphql.bootique/graphql-bootique

@Provides
@Singleton
GraphQL createGraphQL( SchemaTranslator translator) {
  GraphQLSchema schema = translator.toGraphQL();
  return new GraphQL(schema);
}

代码示例来源:origin: com.graphql-java/graphql-java

public GraphQL build() {
    assertNotNull(graphQLSchema, "graphQLSchema must be non null");
    assertNotNull(queryExecutionStrategy, "queryStrategy must be non null");
    assertNotNull(idProvider, "idProvider must be non null");
    return new GraphQL(graphQLSchema, queryExecutionStrategy, mutationExecutionStrategy, subscriptionExecutionStrategy, idProvider, instrumentation, preparsedDocumentProvider);
  }
}

代码示例来源:origin: com.yahoo.elide/elide-graphql

@Inject
public GraphQLEndpoint(
    @Named("elide") Elide elide,
    @Named("elideUserExtractionFunction") DefaultOpaqueUserFunction getUser) {
  log.error("Started ~~");
  this.elide = elide;
  this.elideSettings = elide.getElideSettings();
  this.getUser = getUser;
  PersistentResourceFetcher fetcher = new PersistentResourceFetcher(elide.getElideSettings());
  ModelBuilder builder = new ModelBuilder(elide.getElideSettings().getDictionary(), fetcher);
  this.api = new GraphQL(builder.build());
}

代码示例来源:origin: yahoo/elide

@Inject
public GraphQLEndpoint(
    @Named("elide") Elide elide,
    @Named("elideUserExtractionFunction") DefaultOpaqueUserFunction getUser) {
  log.error("Started ~~");
  this.elide = elide;
  this.elideSettings = elide.getElideSettings();
  this.getUser = getUser;
  PersistentResourceFetcher fetcher = new PersistentResourceFetcher(elide.getElideSettings());
  ModelBuilder builder = new ModelBuilder(elide.getElideSettings().getDictionary(), fetcher);
  this.api = new GraphQL(builder.build());
}

代码示例来源:origin: bpatters/schemagen-graphql

@SuppressWarnings("rawtypes")
private GameDTO getGameNode(String id) throws IOException {
  ExecutionResult result = new GraphQL(schema).execute(String.format("{ node(id:\"%s\") {...on Game {id, name} } }", id));
  assertEquals(0, result.getErrors().size());
  return objectMapper.readValue(objectMapper.writeValueAsString(((Map) result.getData()).get("node")), GameDTO.class);
}

代码示例来源:origin: bpatters/schemagen-graphql

@SuppressWarnings("rawtypes")
private UserDTO getUserNode(String id) throws IOException {
  ExecutionResult result = new GraphQL(schema).execute(String.format("{ node(id:\"%s\") {...on User {id, name, email} } }", id));
  assertEquals(0, result.getErrors().size());
  return objectMapper.readValue(objectMapper.writeValueAsString(((Map) result.getData()).get("node")), UserDTO.class);
}

代码示例来源:origin: bpatters/schemagen-graphql

private DeleteUserPayload deleteUser(String id, String clientMutationId) throws IOException {
  ExecutionResult result = new GraphQL(schema).execute(String
      .format("mutation M { Mutations { deleteUser(input: { id:\"%s\", clientMutationId:\"%s\"}) {clientMutationId} } }", id, clientMutationId));
  assertEquals(0, result.getErrors().size());
  DeleteUserPayload payload = objectMapper.readValue(objectMapper.writeValueAsString(getMutationResults(result, "deleteUser")), DeleteUserPayload.class);
  assertEquals(clientMutationId, payload.getClientMutationId());
  return payload;
}

代码示例来源:origin: bpatters/schemagen-graphql

private DeleteGamePayload deleteGame(String id, String clientMutationId) throws IOException {
  ExecutionResult result = new GraphQL(schema).execute(
      String.format("mutation M { Mutations {deleteGame(input:{ id:\"%s\", clientMutationId:\"%s\"}) {clientMutationId} } }", id, clientMutationId));
  assertEquals(0, result.getErrors().size());
  DeleteGamePayload payload = objectMapper.readValue(objectMapper.writeValueAsString(getMutationResults(result, "deleteGame")), DeleteGamePayload.class);
  assertEquals(clientMutationId, payload.getClientMutationId());
  return payload;
}

代码示例来源:origin: bpatters/schemagen-graphql

private RelayConnection<GameDTO> findGames(int first) throws IOException {
  ExecutionResult result = new GraphQL(schema).execute(String
      .format("{ Queries { games(first:%d) { edges { node {id, name}, cursor } , pageInfo {hasPreviousPage, hasNextPage} } } }", first));
  assertEquals(result.getErrors().toString(), 0, result.getErrors().size());
  return deserialize(objectMapper.writeValueAsString(getQueryResults(result, "games")), new TypeReference<RelayConnection<GameDTO>>() {
  });
}

代码示例来源:origin: bpatters/schemagen-graphql

private NewGamePayload createGame(String name, String clientMutationId) throws IOException {
  NewGameInput input = objectMapper.readValue(String.format("{\"game\":{\"name\":\"%s\"}, \"clientMutationId\":\"%s\" }", name, clientMutationId),
      NewGameInput.class);
  ExecutionResult result = new GraphQL(schema).execute(String.format(
      "mutation M { Mutations { createGame(input:{ game: {name:\"%s\"}, clientMutationId:\"%s\"}) { game {id, name}, clientMutationId } } }",
      name,
      clientMutationId));
  assertEquals(0, result.getErrors().size());
  NewGamePayload payload = objectMapper.readValue(objectMapper.writeValueAsString(getMutationResults(result, "createGame")), NewGamePayload.class);
  assertEquals(name, payload.getGame().getName());
  assertEquals(clientMutationId, payload.getClientMutationId());
  return payload;
}

代码示例来源:origin: bpatters/schemagen-graphql

@SuppressWarnings("unchecked")
@Test
public void testTypeConverterDetection() {
  GraphQLSchema schema = GraphQLSchemaBuilder.newBuilder()
      .registerTypeFactory(new JacksonTypeFactory(new ObjectMapper()))
      .registerGraphQLControllerObjects(ImmutableList.<Object> of(new TypeConverterTest()))
      .build();
  assertEquals("prepend:1", ((Map<String, String>)new GraphQL(schema).execute("{ someStrings }").getData()).get("someStrings"));
}

代码示例来源:origin: bpatters/schemagen-graphql

private NewUserPayload createUser(String name, String email, String clientMutationId) throws IOException {
  ExecutionResult result = new GraphQL(schema).execute(String.format(
      "mutation M { Mutations {createUser(input: { user: { name:\"%s\", email:\"%s\"}, clientMutationId:\"%s\"}) { user {id, name, email}, clientMutationId} } }",
      name,
      email,
      clientMutationId));
  assertEquals(0, result.getErrors().size());
  NewUserPayload payload = objectMapper.readValue(objectMapper.writeValueAsString(getMutationResults(result, "createUser")), NewUserPayload.class);
  assertEquals(name, payload.getUser().getName());
  assertEquals(email, payload.getUser().getEmail());
  assertEquals(clientMutationId, payload.getClientMutationId());
  return payload;
}

代码示例来源:origin: bsideup/graphql-java-reactive

@Test
public void testCompletableFuture() throws Exception {
  ReactiveExecutionStrategy strategy = new ReactiveExecutionStrategy();
  GraphQLSchema schema = newQuerySchema(it -> it
      .field(newStringField("a").dataFetcher(env -> CompletableFuture.completedFuture("static")))
  );
  ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a }");
  Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber);
  subscriber
      .assertChanges(it -> it.containsExactly(
          tuple("00:000", "", ImmutableMap.of("a", "static"))
      ))
      .assertComplete();
}

代码示例来源:origin: bsideup/graphql-java-reactive

@Test
public void testPlainField() throws Exception {
  GraphQLSchema schema = newQuerySchema(it -> it
      .field(newLongField("a").dataFetcher(env -> Flowable.interval(1, SECONDS, scheduler).take(2)))
  );
  ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a }");
  assertThat(executionResult)
      .isNotNull()
      .satisfies(it -> assertThat(it.<Publisher<Change>>getData()).isNotNull().isInstanceOf(Publisher.class));
  Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber);
  scheduler.advanceTimeBy(2, SECONDS);
  subscriber
      .assertChanges(it -> it.containsExactly(
          tuple("01:000", "", ImmutableMap.of("a", 0L)),
          tuple("02:000", "a", 1L)
      ))
      .assertComplete();
}

代码示例来源:origin: nfl/graphql-rxjava

public static void main(String[] args) {
  GraphQLObjectType queryType = newObject()
      .name("helloWorldQuery")
      .field(newFieldDefinition()
          .type(GraphQLString)
          .name("hello")
          .staticValue(Observable.just("world"))
          .build())
      .build();
  GraphQLSchema schema = GraphQLSchema.newSchema()
      .query(queryType)
      .build();
  Observable<?> result = ((RxExecutionResult)new GraphQL(schema, new RxExecutionStrategy()).execute("{hello}")).getDataObservable();
  result.subscribe(System.out::println);
}

代码示例来源:origin: bsideup/graphql-java-reactive

@Test
  public void testStaticValues() throws Exception {
    GraphQLSchema schema = newQuerySchema(it -> it
        .field(newStringField("a").dataFetcher(env -> "staticA"))
        .field(newStringField("b").dataFetcher(env -> "staticB"))
    );

    ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a, b }");

    Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber);

    subscriber
        .assertChanges(it -> it.containsExactly(
            tuple("00:000", "", ImmutableMap.of("a", "staticA", "b", "staticB"))
        ))
        .assertComplete();
  }
}

代码示例来源:origin: bsideup/graphql-java-reactive

@Test
public void testAnyPublisher() throws Exception {
  Duration tick = Duration.ofSeconds(1);
  GraphQLSchema schema = newQuerySchema(it -> it
      // use Flux from Project Reactor
      .field(newLongField("a").dataFetcher(env -> Flux.interval(tick).take(2)))
  );
  ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a }");
  // Use Reactor's StepVerifier
  StepVerifier.withVirtualTime(() -> (Publisher<Change>) executionResult.getData())
      .expectSubscription()
      .expectNoEvent(tick)
      .assertNext(matchChange("", ImmutableMap.of("a", 0L)))
      .expectNoEvent(tick)
      .assertNext(matchChange("a", 1L))
      .verifyComplete();
}

代码示例来源:origin: bsideup/graphql-java-reactive

@Test
public void testStartWith() throws Exception {
  GraphQLSchema schema = newQuerySchema(it -> it
      .field(newLongField("a").dataFetcher(env -> Flowable.interval(1, SECONDS, scheduler).take(2).startWith(-42L)))
  );
  ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a }");
  Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber);
  scheduler.advanceTimeBy(2, SECONDS);
  subscriber
      .assertChanges(it -> it.containsExactly(
          tuple("00:000", "", ImmutableMap.of("a", -42L)),
          tuple("01:000", "a", 0L),
          tuple("02:000", "a", 1L)
      ))
      .assertComplete();
}

相关文章